This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [PATCH] Avoid signed overflow in num_get::_M_extract_int (PR libstdc++/67214)
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: Xi Ruoyao <ryxi at stu dot xidian dot edu dot cn>
- Cc: gcc-patches at gcc dot gnu dot org, libstdc++ at gcc dot gnu dot org
- Date: Fri, 19 May 2017 15:38:36 +0100
- Subject: Re: [PATCH] Avoid signed overflow in num_get::_M_extract_int (PR libstdc++/67214)
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jwakely at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 174077F415
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 174077F415
- References: <1495105840.1663.4.camel@stu.xidian.edu.cn>
On 18/05/17 19:10 +0800, Xi Ruoyao wrote:
This UB has been hiding so long...
Indeed! Thanks for the patch.
2017-03-11 Xi Ruoyao <ryxi@stu.xidian.edu.cn>
PR libstdc++/67214
* include/bits/locale_facets.tcc (_M_extract_int):
Add explicit conversion to avoid signed overflow.
---
libstdc++-v3/include/bits/locale_facets.tcc | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc
index 351190c..5f85d15 100644
--- a/libstdc++-v3/include/bits/locale_facets.tcc
+++ b/libstdc++-v3/include/bits/locale_facets.tcc
@@ -470,7 +470,8 @@ _GLIBCXX_BEGIN_NAMESPACE_LDBL
bool __testoverflow = false;
const __unsigned_type __max =
(__negative && __gnu_cxx::__numeric_traits<_ValueT>::__is_signed)
- ? -__gnu_cxx::__numeric_traits<_ValueT>::__min
+ ? -static_cast<__unsigned_type>(__gnu_cxx::
+ __numeric_traits<_ValueT>::__min)
Do we need to keep the negation, or can we just cast to
__unsigned_type?