localename.cc (locale::_Impl::_Impl(const char*, size_t)): Improve previous fix for...
authorPaolo Carlini <pcarlini@unitus.it>
Thu, 28 Nov 2002 17:29:24 +0000 (18:29 +0100)
committerPaolo Carlini <paolo@gcc.gnu.org>
Thu, 28 Nov 2002 17:29:24 +0000 (17:29 +0000)
2002-11-28  Paolo Carlini  <pcarlini@unitus.it>
    Nathan Myers  <ncm@cantrip.org>

* src/localename.cc
(locale::_Impl::_Impl(const char*, size_t)):
Improve previous fix for the strtok vs MT issue.

Co-Authored-By: Nathan Myers <ncm@cantrip.org>
From-SVN: r59609

libstdc++-v3/ChangeLog
libstdc++-v3/src/localename.cc

index c6225197616195a762e9fe1c035a0985395a7b8c..b18948e3f079e2ae68aa704363fcd9d22775d165 100644 (file)
@@ -1,3 +1,10 @@
+2002-11-28  Paolo Carlini  <pcarlini@unitus.it>
+            Nathan Myers  <ncm@cantrip.org>
+
+       * src/localename.cc
+       (locale::_Impl::_Impl(const char*, size_t)):
+       Improve previous fix for the strtok vs MT issue.
+
 2002-11-28  Paolo Carlini  <pcarlini@unitus.it>
 
        * config/locale/gnu/c_locale.cc (locale::_S_categories):
index daed6f1f20326853c3b5ede3c20da897c02dd0e6..892a951ce0d1bb5832187ea01b445944bf968a8e 100644 (file)
@@ -141,37 +141,31 @@ namespace std
       }
 
     // Name all the categories.
-    size_t __len = strlen(__s) + 1;
+    size_t __len = strlen(__s);
     if (!strchr(__s, ';'))
       {
        for (size_t __i = 0; 
             __i < _S_categories_size + _S_extra_categories_size; ++__i)
          {
-           _M_names[__i] = new char[__len];
+           _M_names[__i] = new char[__len + 1];
            strcpy(_M_names[__i], __s);
          }
       }
     else
-     {
-       char* __new;
-       const char* __save = __s;
-       char* __next = strpbrk(__save, "=;");
-       __save = __next + 1;
+      {
+       const char* __beg = __s;
        for (size_t __i = 0; 
-            __i < _S_categories_size + _S_extra_categories_size - 1; ++__i)
+            __i < _S_categories_size + _S_extra_categories_size; ++__i)
          {
-           __next = strpbrk(__save, "=;");
-           __new = new char[__next - __save + 1];
-           memcpy(__new, __save, __next - __save);
-           __new[__next - __save] = '\0';
+           __beg = strchr(__beg, '=') + 1;
+           const char* __end = strchr(__beg, ';');
+           if (!__end)
+             __end = __s + __len;
+           char* __new = new char[__end - __beg + 1];
+           memcpy(__new, __beg, __end - __beg);
+           __new[__end - __beg] = '\0';
            _M_names[__i] = __new;
-           __save = __next + 1;
-           __next = strpbrk(__save, "=;");
-           __save = __next + 1;
          }
-       __new = new char[__s + __len - __save];
-       memcpy(__new, __save, __s + __len - __save);
-       _M_names[_S_categories_size + _S_extra_categories_size - 1] = __new;
       }
 
     // Construct all standard facets and add them to _M_facets.