This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[v3] Improve the fix for strtok vs MT


Hi,

tested x86-linux. That's it (for now, at least ;)

Ciao,
Paolo.

//////////
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.
*** localename.cc.~1.32.~	Tue Nov 26 01:06:54 2002
--- localename.cc	Thu Nov 28 00:17:10 2002
*************** namespace std
*** 141,177 ****
        }
  
      // Name all the categories.
!     size_t __len = strlen(__s) + 1;
      if (!strchr(__s, ';'))
        {
  	for (size_t __i = 0; 
  	     __i < _S_categories_size + _S_extra_categories_size; ++__i)
  	  {
! 	    _M_names[__i] = new char[__len];
  	    strcpy(_M_names[__i], __s);
  	  }
        }
      else
!      {
! 	char* __new;
! 	const char* __save = __s;
! 	char* __next = strpbrk(__save, "=;");
! 	__save = __next + 1;
  	for (size_t __i = 0; 
! 	     __i < _S_categories_size + _S_extra_categories_size - 1; ++__i)
  	  {
! 	    __next = strpbrk(__save, "=;");
! 	    __new = new char[__next - __save + 1];
! 	    memcpy(__new, __save, __next - __save);
! 	    __new[__next - __save] = '\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.  
--- 141,171 ----
        }
  
      // Name all the categories.
!     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 + 1];
  	    strcpy(_M_names[__i], __s);
  	  }
        }
      else
!       {
! 	const char* __beg = __s;
  	for (size_t __i = 0; 
! 	     __i < _S_categories_size + _S_extra_categories_size; ++__i)
  	  {
! 	    __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;
! 	  }
        }
  
      // Construct all standard facets and add them to _M_facets.  

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]