From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 18D053857B89; Mon, 8 Aug 2022 15:10:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 18D053857B89 From: "phdiv at fastmail dot fm" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 10.3.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: phdiv at fastmail dot fm X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Aug 2022 15:10:59 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106559 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=3D53426&action=3Dedit Reproducer. > cat w.cpp extern char buffer[64]; extern unsigned int number[16]; void f(){ static const char string[16][3]=3D{ "01","02","03","04","05","06","07","08", "09","10","11","12","13","14","15","16"}; for(unsigned int i=3D0; 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 t= he last format character [-Wformat-truncation=3D] 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=20 https://godbolt.org/z/PvfrchP7E .=