[PATCH] avoid eliminating snprintf(d, n, ...) whose zero size comes from a range (PR 79496)

Martin Sebor msebor@gmail.com
Mon Feb 13 20:25:00 GMT 2017


When the size of the destination in a call to snprintf is in
a range, at level 1 -Wformat-truncation uses the upper bound
as the size while the stricter level 2 uses the lower bound.
However, when the lower bound is zero treating it the same as
a constant zero and optimizing the call into a constant isn't
correct because the actual argument need not be zero and the
output of the function is important.  The attached patch
avoids this unsafe transformation.

Is this okay for trunk?

Martin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-79496.diff
Type: text/x-patch
Size: 2989 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20170213/8148d4dc/attachment.bin>


More information about the Gcc-patches mailing list