This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH 4/7] Fix int overflow
- From: Mikhail Maltsev <maltsevm at gmail dot com>
- To: Jeff Law <law at redhat dot com>, gcc-patches <gcc-patches at gnu dot org>, Jason Merrill <jason at redhat dot com>
- Date: Tue, 07 Jul 2015 03:04:53 +0300
- Subject: Re: [PATCH 4/7] Fix int overflow
- Authentication-results: sourceware.org; auth=none
- References: <559AD66D dot 1070809 at gmail dot com> <559AD8CA dot 8030209 at gmail dot com> <559B0752 dot 6060603 at redhat dot com>
On 07.07.2015 1:55, Jeff Law wrote:
>> len = d_number (di);
>> - if (len <= 0)
>> + if (len <= 0 || len > INT_MAX)
>> return NULL;
>> ret = d_identifier (di, len);
>> di->last_name = ret;
> Isn't this only helpful if sizeof (long) > sizeof (int)? Otherwise the
> compiler is going to eliminate that newly added test, right?
>
> So with that in mind, what happens on i686-unknown-linux with this test?
>
>
> Jeff
>
Probably it should be fine, because the problem occurred when len became
negative after implicit conversion to int (d_identifier does not check
for negative length, but it does check that length does not exceed total
string length). In this case (i.e. on ILP32 targets) len will not change
sign after conversion to int (because it's a no-op).
I'm not completely sure about compiler warnings, but AFAIR, in multilib
build libiberty is also built for 32-bit target, and I did not get any
additional warnings.
--
Regards,
Mikhail Maltsev