Commit 157f3283 by Paolo Carlini Committed by Paolo Carlini

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

	* include/bits/locale_facets.tcc
	(money_get<>::do_get(..., string_type&)): Absolutely avoid
	dereferencing end iterators; general clean up.

From-SVN: r73011
parent 4e81efd4
2003-10-28 Paolo Carlini <pcarlini@suse.de> 2003-10-28 Paolo Carlini <pcarlini@suse.de>
* include/bits/locale_facets.tcc
(money_get<>::do_get(..., string_type&)): Absolutely avoid
dereferencing end iterators; general clean up.
2003-10-28 Paolo Carlini <pcarlini@suse.de>
* include/bits/locale_facets.tcc (time_get::_M_extract_num): * include/bits/locale_facets.tcc (time_get::_M_extract_num):
Absolutely avoid dereferencing end iterators. Absolutely avoid dereferencing end iterators.
(time_get::_M_extract_name): Likewise. (time_get::_M_extract_name): Likewise.
......
...@@ -1144,9 +1144,9 @@ namespace std ...@@ -1144,9 +1144,9 @@ namespace std
const money_base::pattern __p = __intl ? __mpt.neg_format() const money_base::pattern __p = __intl ? __mpt.neg_format()
: __mpf.neg_format(); : __mpf.neg_format();
const string_type __pos_sign =__intl ? __mpt.positive_sign() const string_type __pos_sign = __intl ? __mpt.positive_sign()
: __mpf.positive_sign(); : __mpf.positive_sign();
const string_type __neg_sign =__intl ? __mpt.negative_sign() const string_type __neg_sign = __intl ? __mpt.negative_sign()
: __mpf.negative_sign(); : __mpf.negative_sign();
const char_type __d = __intl ? __mpt.decimal_point() const char_type __d = __intl ? __mpt.decimal_point()
: __mpf.decimal_point(); : __mpf.decimal_point();
...@@ -1169,9 +1169,9 @@ namespace std ...@@ -1169,9 +1169,9 @@ namespace std
// The tentative returned string is stored here. // The tentative returned string is stored here.
string_type __tmp_units; string_type __tmp_units;
char_type __c = *__beg;
for (int __i = 0; __beg != __end && __i < 4 && __testvalid; ++__i) for (int __i = 0; __beg != __end && __i < 4 && __testvalid; ++__i)
{ {
char_type __c;
const part __which = static_cast<part>(__p.field[__i]); const part __which = static_cast<part>(__p.field[__i]);
switch (__which) switch (__which)
{ {
...@@ -1190,12 +1190,8 @@ namespace std ...@@ -1190,12 +1190,8 @@ namespace std
: __mpf.curr_symbol(); : __mpf.curr_symbol();
const size_type __len = __symbol.size(); const size_type __len = __symbol.size();
size_type __j = 0; size_type __j = 0;
while (__beg != __end for (; __beg != __end && __j < __len
&& __j < __len && __symbol[__j] == __c) && *__beg == __symbol[__j]; ++__beg, ++__j);
{
__c = *(++__beg);
++__j;
}
// When (__io.flags() & ios_base::showbase) // When (__io.flags() & ios_base::showbase)
// symbol is required. // symbol is required.
if (__j != __len && (__io.flags() & ios_base::showbase)) if (__j != __len && (__io.flags() & ios_base::showbase))
...@@ -1204,15 +1200,15 @@ namespace std ...@@ -1204,15 +1200,15 @@ namespace std
break; break;
case money_base::sign: case money_base::sign:
// Sign might not exist, or be more than one character long. // Sign might not exist, or be more than one character long.
if (__pos_sign.size() && __c == __pos_sign[0]) if (__pos_sign.size() && *__beg == __pos_sign[0])
{ {
__sign = __pos_sign; __sign = __pos_sign;
__c = *(++__beg); ++__beg;
} }
else if (__neg_sign.size() && __c == __neg_sign[0]) else if (__neg_sign.size() && *__beg == __neg_sign[0])
{ {
__sign = __neg_sign; __sign = __neg_sign;
__c = *(++__beg); ++__beg;
} }
else if (__pos_sign.size() && __neg_sign.size()) else if (__pos_sign.size() && __neg_sign.size())
{ {
...@@ -1223,12 +1219,13 @@ namespace std ...@@ -1223,12 +1219,13 @@ namespace std
case money_base::value: case money_base::value:
// Extract digits, remove and stash away the // Extract digits, remove and stash away the
// grouping of found thousands separators. // grouping of found thousands separators.
while (__beg != __end for (; __beg != __end; ++__beg)
&& (__ctype.is(ctype_base::digit, __c) if (__ctype.is(ctype_base::digit, __c = *__beg))
|| (__c == __d && !__testdecfound)
|| __c == __sep))
{ {
if (__c == __d) __tmp_units += __c;
++__sep_pos;
}
else if (__c == __d && !__testdecfound)
{ {
__grouping_tmp += static_cast<char>(__sep_pos); __grouping_tmp += static_cast<char>(__sep_pos);
__sep_pos = 0; __sep_pos = 0;
...@@ -1249,33 +1246,26 @@ namespace std ...@@ -1249,33 +1246,26 @@ namespace std
} }
} }
else else
{ break;
__tmp_units += __c;
++__sep_pos;
}
__c = *(++__beg);
}
break; break;
case money_base::space: case money_base::space:
case money_base::none: case money_base::none:
// Only if not at the end of the pattern. // Only if not at the end of the pattern.
if (__i != 3) if (__i != 3)
while (__beg != __end for (; __beg != __end
&& __ctype.is(ctype_base::space, __c)) && __ctype.is(ctype_base::space, *__beg); ++__beg);
__c = *(++__beg);
break; break;
} }
} }
// Need to get the rest of the sign characters, if they exist. // Need to get the rest of the sign characters, if they exist.
const char_type __eof = static_cast<char_type>(char_traits<char_type>::eof());
if (__sign.size() > 1) if (__sign.size() > 1)
{ {
const size_type __len = __sign.size(); const size_type __len = __sign.size();
size_type __i = 1; size_type __i = 1;
for (; __c != __eof && __i < __len; ++__i) for (; __beg != __end && __i < __len; ++__i)
while (__beg != __end && __c != __sign[__i]) for (; __beg != __end
__c = *(++__beg); && *__beg != __sign[__i]; ++__beg);
if (__i != __len) if (__i != __len)
__testvalid = false; __testvalid = false;
...@@ -1320,7 +1310,7 @@ namespace std ...@@ -1320,7 +1310,7 @@ namespace std
__testvalid = false; __testvalid = false;
// Iff no more characters are available. // Iff no more characters are available.
if (__c == __eof) if (__beg == __end)
__err |= ios_base::eofbit; __err |= ios_base::eofbit;
// Iff valid sequence is not recognized. // Iff valid sequence is not recognized.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment