2012-10-10  Liviu Nicoara  <lnico...@apache.org>

    * src/collate.cpp (__rw_strnxfrm): preserved embedded NULs

Index: src/collate.cpp
===================================================================
--- src/collate.cpp     (revision 1392832)
+++ src/collate.cpp     (working copy)
@@ -547,7 +547,7 @@
 
         _TRY {
             // resize the result string to fit itself plus the result
-            // of the transformation including the terminatin NUL
+            // of the transformation including the terminating NUL
             // appended by strxfrm()
             res.resize (res_size + dst_size + 1);
         }
@@ -557,36 +557,15 @@
             _RETHROW;
         }
 
-        // transfor the source string up to the terminating NUL
-        size_t xfrm_size =
-            strxfrm (&res [0] + res_size, psrc, dst_size + 1);
-
-#if defined _MSC_VER && _MSC_VER < 1400
-        // compute the correct value that should have been returned from
-        // strxfrm() after the transformation has completed (MSVC strxfrm()
-        // returns a bogus result; see PR #29935)
-        xfrm_size = strlen (&res [0] + res_size);
-#endif   // MSVC < 8.0
-
-        // increment the size of the result string by the number
-        // of transformed characters excluding the terminating NUL
-        // if strxfrm() transforms the empty string into the empty
-        // string, keep the terminating NUL, otherwise drop it
-        res_size += xfrm_size + (last && !*psrc && !xfrm_size);
-
-        _TRY {
-            res.resize (res_size);
-        }
-        _CATCH (...) {
-            if (pbuf != buf)
-                delete[] pbuf;
-            _RETHROW;
-        }
+        strxfrm (&res [0] + res_size, psrc, dst_size + 1);
     }
 
     if (pbuf != buf)
         delete[] pbuf;
 
+    if (!res.empty ())
+        res.resize (res.size () - 1);
+
     return res;
 }
 

Reply via email to