public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "phdiv at fastmail dot fm" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/106559] New: Spurious warning format-truncation (regression from 9)
Date: Mon, 08 Aug 2022 15:10:58 +0000	[thread overview]
Message-ID: <bug-106559-4@http.gcc.gnu.org/bugzilla/> (raw)

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 .

             reply	other threads:[~2022-08-08 15:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-08 15:10 phdiv at fastmail dot fm [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-106559-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).