locale_facets.tcc (time_get::_M_extract_num): Absolutely avoid dereferencing end iterators.

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.

From-SVN: r73004
This commit is contained in:
Paolo Carlini 2003-10-28 12:23:31 +00:00 committed by Paolo Carlini
parent 699a49253d
commit cc27f5a21c
2 changed files with 24 additions and 18 deletions

View File

@ -1,3 +1,14 @@
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.
2003-10-27 Paolo Carlini <pcarlini@suse.de> 2003-10-27 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/12778 PR libstdc++/12778

View File

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