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] use zero as the lower bound for a signed-unsigned range (PR 79327)


On 02/03/2017 12:02 PM, Jeff Law wrote:
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.

Let's let Jakub go first so he can be done with his day/week.
I'll deal with the conflicts and retest everything.

Martin


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