This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] Minor tweak to num_get::_M_extract_int
- From: Paolo Carlini <pcarlini at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 09 Dec 2003 20:39:40 +0100
- Subject: [v3] Minor tweak to num_get::_M_extract_int
Hi,
one (that for the sign) is trivial. The other, almost (considering
for simplicity the !__negative case only): if __result == 0 no
overflow is possible; if __result > 0 but still <= __max, when
multiplied by __base (8, 10 or 16) and summed to __digit, the
total is either strictly > __result or strictly < __result (overflow).
Tested x86-linux, I'm committing to mainline in a moment.
Paolo.
/////////////
2003-12-09 Paolo Carlini <pcarlini@suse.de>
* include/bits/locale_facets.tcc (num_get::_M_extract_int):
Slightly streamline the code dealing with overflows and the
parsing of the sign.
diff -prN libstdc++-v3-orig/include/bits/locale_facets.tcc libstdc++-v3/include/bits/locale_facets.tcc
*** libstdc++-v3-orig/include/bits/locale_facets.tcc Mon Dec 8 09:44:42 2003
--- libstdc++-v3/include/bits/locale_facets.tcc Tue Dec 9 19:52:33 2003
*************** namespace std
*** 283,291 ****
bool __negative = false;
if (__beg != __end)
{
! __negative = __traits_type::eq(*__beg, __lit[_S_iminus]);
! if (__negative && numeric_limits<_ValueT>::is_signed
! || __traits_type::eq(*__beg, __lit[_S_iplus]))
++__beg;
}
--- 283,291 ----
bool __negative = false;
if (__beg != __end)
{
! if (numeric_limits<_ValueT>::is_signed)
! __negative = __traits_type::eq(*__beg, __lit[_S_iminus]);
! if (__negative || __traits_type::eq(*__beg, __lit[_S_iplus]))
++__beg;
}
*************** namespace std
*** 353,360 ****
else
{
const _ValueT __new_result = __result * __base - __digit;
! if (__result)
! __overflow |= __new_result >= __result;
__result = __new_result;
++__sep_pos;
__found_num = true;
--- 353,359 ----
else
{
const _ValueT __new_result = __result * __base - __digit;
! __overflow |= __new_result > __result;
__result = __new_result;
++__sep_pos;
__found_num = true;
*************** namespace std
*** 398,405 ****
else
{
const _ValueT __new_result = __result * __base + __digit;
! if (__result)
! __overflow |= __new_result <= __result;
__result = __new_result;
++__sep_pos;
__found_num = true;
--- 397,403 ----
else
{
const _ValueT __new_result = __result * __base + __digit;
! __overflow |= __new_result < __result;
__result = __new_result;
++__sep_pos;
__found_num = true;
*************** namespace std
*** 436,443 ****
__err |= ios_base::failbit;
}
! if (!(__err & ios_base::failbit)
! && !__overflow && __found_num)
__v = __result;
else
__err |= ios_base::failbit;
--- 434,441 ----
__err |= ios_base::failbit;
}
! if (!(__err & ios_base::failbit) && !__overflow
! && __found_num)
__v = __result;
else
__err |= ios_base::failbit;