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] Some locale_facets work


Hi,

tested x86-linux, committed.

Paolo.

//////////
2003-10-28  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/locale_facets.tcc (time_get::_M_extract_num):
	Absolutely avoid dereferencing end iterators.
	(time_get::_M_extract_name): Likewise.

	* include/bits/locale_facets.tcc
	(time_get::_M_extract_via_format, case 'e'): Don't try to
	be smart wrt returning the right __beg in case of parse
	error, time_get::_M_extract_num must be fixed instead.

diff -urN libstdc++-v3-orig/include/bits/locale_facets.tcc libstdc++-v3/include/bits/locale_facets.tcc
--- libstdc++-v3-orig/include/bits/locale_facets.tcc	2003-10-27 17:21:12.000000000 +0100
+++ libstdc++-v3/include/bits/locale_facets.tcc	2003-10-28 12:55:00.000000000 +0100
@@ -1619,11 +1619,9 @@
 		  if (__ctype.is(ctype_base::space, *__beg))
 		    _M_extract_num(++__beg, __end, __tm->tm_mday, 1, 9, 1,
 				   __ctype, __err);
-		  else if (*__beg != __ctype.widen('0'))
+		  else
 		    _M_extract_num(__beg, __end, __tm->tm_mday, 10, 31, 2,
 				   __ctype, __err);		    
-		  else
-		    __err |= ios_base::failbit;
 		  break;		    
 		case 'D':
 		  // Equivalent to %m/%d/%y.[tm_mon, tm_mday, tm_year]
@@ -1763,14 +1761,9 @@
       size_t __i = 0;
       string __digits;
       bool __testvalid = true;
-      char_type __c = *__beg;
-      while (__beg != __end && __i < __len 
-	     && __ctype.is(ctype_base::digit, __c)) 
-	{
-	  __digits += __ctype.narrow(__c, 0);
-	  __c = *(++__beg);
-	  ++__i;
-	}
+      for (; __beg != __end && __i < __len 
+	     && __ctype.is(ctype_base::digit, *__beg); ++__beg, ++__i) 
+	__digits += __ctype.narrow(*__beg, 0);
       if (__i == __len)
 	{
 	  const int __value = std::atoi(__digits.c_str());
@@ -1802,11 +1795,14 @@
       bool __testvalid = true;
       const char_type* __name;
 
-      char_type __c = *__beg;
       // Look for initial matches.
-      for (size_t __i1 = 0; __i1 < __indexlen; ++__i1)
-	if (__c == __names[__i1][0])
-	  __matches[__nmatches++] = __i1;
+      if (__beg != __end)
+	{
+	  const char_type __c = *__beg;
+	  for (size_t __i1 = 0; __i1 < __indexlen; ++__i1)
+	    if (__c == __names[__i1][0])
+	      __matches[__nmatches++] = __i1;
+	}
       
       while (__nmatches > 1)
 	{
@@ -1815,15 +1811,14 @@
 	  for (size_t __i2 = 0; __i2 < __nmatches; ++__i2)
 	    __minlen = std::min(__minlen, 
 				__traits_type::length(__names[__matches[__i2]]));
-	  
+	  ++__beg;
 	  if (__pos < __minlen && __beg != __end)
 	    {
 	      ++__pos;
-	      __c = *(++__beg);
 	      for (size_t __i3 = 0; __i3 < __nmatches; ++__i3)
 		{
 		  __name = __names[__matches[__i3]];
-		  if (__name[__pos] != __c)
+		  if (__name[__pos] != *__beg)
 		    __matches[__i3] = __matches[--__nmatches];
 		}
 	    }

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