On 02/13/2017 01:11 PM, Martin Sebor wrote:
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

gcc-79496.diff


PR middle-end/79496 - call to snprintf with zero size eliminated with 
-Wformat-truncation=2

gcc/ChangeLog:

        PR middle-end/79496
        * gimple-ssa-sprintf.c (pass_sprintf_length::handle_gimple_call): Avoid
        clearing info.nowrite flag when snprintf size argument is a range.

gcc/testsuite/ChangeLog:

        PR middle-end/79496
        * gcc.dg/tree-ssa/builtin-snprintf-2.c: New test.
OK.
jeff

Reply via email to