public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/106559] New: Spurious warning format-truncation (regression from 9)
@ 2022-08-08 15:10 phdiv at fastmail dot fm
  2022-08-09  7:37 ` [Bug tree-optimization/106559] [10/11/12/13 Regression] Spurious warning -Wformat-truncation " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: phdiv at fastmail dot fm @ 2022-08-08 15:10 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106559
           Summary: Spurious warning format-truncation (regression from 9)
           Product: gcc
           Version: 10.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: phdiv at fastmail dot fm
  Target Milestone: ---

Created attachment 53426
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53426&action=edit
Reproducer.

> cat w.cpp
extern char buffer[64];
extern unsigned int number[16];

void f(){
  static const char string[16][3]={
      "01","02","03","04","05","06","07","08",
      "09","10","11","12","13","14","15","16"};

  for(unsigned int i=0; i<16; ++i)
    __builtin_snprintf(buffer,sizeof(buffer),"%u (%s):   %8x",
      i,string[i],number[i]);
}

> g++ -O1 -Wformat-truncation -c w.cpp
w.cpp: In function 'void f()':
w.cpp:10:61: warning: '__builtin_snprintf' output may be truncated before the
last format character [-Wformat-truncation=]
   10 |     __builtin_snprintf(buffer,sizeof(buffer),"%u (%s):   %8x",
      |                                                             ^
w.cpp:10:23: note: '__builtin_snprintf' output between 17 and 65 bytes into a
destination of size 64
   10 |     __builtin_snprintf(buffer,sizeof(buffer),"%u (%s):   %8x",
      |     ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   11 |       i,string[i],number[i]);
      |       ~~~~~~~~~~~~~~~~~~~~~~


Granted, the documentation of Wformat-truncation mentions possible false
positives, but this is a regression in GCC 10 with respect to GCC 9
(and present up to trunk).

For some more variations which do or do not exhibit this bug, see 
https://godbolt.org/z/PvfrchP7E .

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-07-07 10:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-08 15:10 [Bug middle-end/106559] New: Spurious warning format-truncation (regression from 9) phdiv at fastmail dot fm
2022-08-09  7:37 ` [Bug tree-optimization/106559] [10/11/12/13 Regression] Spurious warning -Wformat-truncation " rguenth at gcc dot gnu.org
2022-08-16 16:00 ` msebor at gcc dot gnu.org
2022-12-14  2:28 ` pinskia at gcc dot gnu.org
2023-07-07 10:43 ` [Bug tree-optimization/106559] [11/12/13/14 " rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).