From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 00DA73858C42; Mon, 18 Mar 2024 08:29:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 00DA73858C42 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1710750547; bh=EuYK9T+nnUnnqsa+PIzFVeGfWA2yIjjpOCzGjT0SxCw=; h=From:To:Subject:Date:From; b=gYK78QKqb8OlPVn5boQp3SBFGx2/BtA3Bho4F/itjYroOFxzCiX3Rfmi3LyJ3S3ei Fg2pSf9cVcV7CtE2bWz/rNECEodsIgTmibbe8+AeJHl9iZOReKbAChOaT5NGmtLQj1 +f2G5C7wNximYt9phsQ8nppaka3ns7VLOiSTLzgI= From: "torsten.mandel at sap dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/114374] New: [12/13 Regression] snprintf Wformat-truncation Date: Mon, 18 Mar 2024 08:29:05 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 13.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: torsten.mandel at sap dot com 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 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114374 Bug ID: 114374 Summary: [12/13 Regression] snprintf Wformat-truncation Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: torsten.mandel at sap dot com Target Milestone: --- Source: // =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D #include "stdio.h" int main() { char buf[11]; int loop(1); do { snprintf(buf,sizeof(buf),"%d",loop++); } while(true); } // =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Compiled with: gcc -Wall triggers: ./buffertest.cpp: In function =E2=80=98int main()=E2=80=99: ./buffertest.cpp:8:37: warning: =E2=80=98snprintf=E2=80=99 output may be tr= uncated before the last format character [-Wformat-truncation=3D] 8 | snprintf(buf,sizeof(buf),"%d",loop++); | ^ ./buffertest.cpp:8:17: note: =E2=80=98snprintf=E2=80=99 output between 2 an= d 12 bytes into a destination of size 11 8 | snprintf(buf,sizeof(buf),"%d",loop++); | ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~ when using gcc-12 and gcc-13; gcc-11 compiled without error. Replacing loop++ with ++loop does not trigger the error; neither case shoul= d be an error as the overflow is UB in both cases and only positive numbers shou= ld be considered regarding the target buffer size.=