https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80924

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
The full output is the following (please include the full diagnostic in bug
reports, not just the notes):

a.c:4:34: warning: ‘snprintf’ output may be truncated before the last format
character [-Wformat-truncation=]
         snprintf(buf,5,"-%d",idx);
                        ^~~~~
a.c:4:9: note: ‘__builtin_snprintf’ output between 3 and 6 bytes into a
destination of size 5
         snprintf(buf,5,"-%d",idx);
         ^~~~~~~~~~~~~~~~~~~~~~~~~

Compiling the test case with -fdump-tree-printf-return-value shows the
following:

a.c:4: __builtin_snprintf: objsize = 5, fmtstr = "-%d"
  Directive 1 at offset 0: "-", length = 1
    Result: 1, 1, 1, 1 (1, 1, 1, 1)
  Directive 2 at offset 1: "%d"
    Result: 1, 4, 4, 4 (2, 5, 5, 5)
  Directive 3 at offset 3: "", length = 1

(The Result: consists of the minimum, likely, maximum, and unlikely maximum
number of bytes output by each directive, with running totals for the four
counters in parentheses.)

The VR_RANGE reported by get_range_info() to the warning pass is [0, 1000].

(gdb) p min
$4 = {<wide_int_storage> = {val = {0, 1000, 140737488345088}, len = 1,
precision = 32}, static is_sign_extended = true}
(gdb) p max
$5 = {<wide_int_storage> = {val = {1000, 140737221856280, -1}, len = 1,
precision = 32}, static is_sign_extended = true}

I suspect the root cause is the same as in bug 78969 and this is a dupe of the
latter.  (Please reopen this bug if you think otherwise.)

*** This bug has been marked as a duplicate of bug 78969 ***

Reply via email to