[PATCH] use zero as the lower bound for a signed-unsigned range (PR 79327)

Jeff Law law@redhat.com
Fri Feb 3 19:02:00 GMT 2017


On 02/02/2017 05:31 PM, Martin Sebor wrote:
>>>> -  T (2, "%#hho",        a);     /* { dg-warning "nul past the end"
>>>> } */
>>>> -  T (2, "%#hhx",        a);     /* { dg-warning ".%#hhx. directive
>>>> writing between 3 and . bytes into a region of size 2" } */
>>>> +  T (2, "%#hho",        a);
>>>> +  T (2, "%#hhx",        a);
>>
>> On reflection, this isn't quite the right fix.  We want to both set
>> the correct range and warn because the call will likely overflow.
>> This is an example of why the likely/unlikely counters have been
>> introduced.  By setting min = 1 and likely = 2 for the %#hho and
>> 3 for the %#hhx we get the desired result.
>
> Attached is a simple patch that removes the vestigial setting of
> the minimum counter while preserving the warnings above by using
> the likely counter.
>
> I had overlooked this when I introduced the likely counter and so
> in the corner cases of "%#o" and "%#x" with a non-constant argument
> that could be zero, the minimum counter would be set to 2 and 3
> respectively rather than 1 (because zero is formatted without
> the '0' or '0x' base prefix).
This patch almost certainly conflicts with Jakub's.  But I think if 
anything it may get simpler after Jakub applies his patch.

Jakub, if you want to do the updates and commit after your patch so they 
can both get into any potential weekend gcc spin for Fedora, go right 
ahead :-)

Otherwise it's good to go for Martin after making the minor updates.

jeff



More information about the Gcc-patches mailing list