On 01/04/2017 02:43 PM, Martin Sebor wrote:
The attached patch corrects an off-by-one mistake in handling
non-zero precisions in signed conversions (%d and %i) with
negative arguments, such as in sprintf(d, "%.2", -1). The call
which results in the three bytes "-01" on output, not 2. I.e.,
the minus sign must be taken into consideration.
Thanks
Martin
gcc-78910.diff
PR tree-optimization/78910 - Wrong print-return-value for a negative number
gcc/ChangeLog:
PR tree-optimization/78910
* gimple-ssa-sprintf.c (tree_digits): Add an argument.
(format_integer): Correct off-by-one error in the handling
of precision with negative numbers in signed conversions..
gcc/testsuite/ChangeLog:
PR tree-optimization/78910
* gcc.dg/tree-ssa/builtin-sprintf-warn-7.c: Adjust text of expected
diagnostics.
* gcc.dg/tree-ssa/builtin-sprintf.c: Add test cases.
* gcc.dg/tree-ssa/pr78910.c: New test.
OK.
jeff