This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 4/7] Fix int overflow


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]