This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] gdb fix for count overflow check
- From: Joel Brobecker <brobecker at adacore dot com>
- To: Eric Lubin <eric at lubin dot us>
- Cc: gdb-patches at sourceware dot org
- Date: Mon, 9 Dec 2013 09:07:41 +0100
- Subject: Re: [PATCH] gdb fix for count overflow check
- Authentication-results: sourceware.org; auth=none
- References: <142420DF-DBAD-4C5C-A71B-7855D34D4665 at lubin dot us>
Hello Eric,
> There is a bug in the overflow check. The overflow check tries to
> assume that signed integers will wrap around on overflow, and thus a
> number that wraps around after a multiplication by 10 should no longer
> be divisible by 10. Unfortunately, signed integer overflow is
> undefined behavior (see section 2.3 of
> http://pdos.csail.mit.edu/papers/ub:apsys12.pdf). and a check for
> signed integer overflow can be optimized out by the compiler. Thus,
> the check for whether count is not divisible by 10 can be optimized to
> false by compilers, therefore rendering the error check useless. To
> mitigate this problem, we check whether the multiplication will
> overflow, before the operation, by comparing count to INT_MAX/ 10. An
> integer will overflow when multiplied by 10 if and only if that
> integer is larger than floor(INT_MAX / 10).
>
>
> CHANGELOG:
> 2013-12-07 Eric Lubin <eric@lubin.us>
>
> * libiberty/cplus-dem.c: Fixed an integer overflow check.
Thanks for the patch. The file you are changing is actually shared
between the GCC and binutils-gdb projects, but under GCC maintainership.
So, would you mind re-sending the patch to gcc-patches@gcc.gnu.org?
Once approved there, it's OK to sync the copy in binutils-gdb.git.
Thank you,
--
Joel