From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BC4263858CDB; Fri, 26 May 2023 07:17:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC4263858CDB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685085443; bh=RfelJiudqsWb3UnKenBjq+o9J6djScqHdMJ06PBIOoE=; h=From:To:Subject:Date:From; b=MvnN2ZqZ/trXmZovusaMQGqMzvsMS6rWc1wRc9Q+cADLZ1PXte2/WS9g1TasCN8+J wUFxi/ENSQ7MxnvNluRYNXGtyMWd9lRbZQMzFM+ESJK7fMRBjABsDkn4QMspek8gDz 5ICEMbM6oLeEUUiULnQ7UszKHzu+eoZJqCXDDe2o= From: "vincent-gcc at vinc17 dot net" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/109979] New: [12 Regression] -Wformat-overflow false positive for %d and non-basic expression Date: Fri, 26 May 2023 07:17:23 +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: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vincent-gcc at vinc17 dot net 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=3D109979 Bug ID: 109979 Summary: [12 Regression] -Wformat-overflow false positive for %d and non-basic expression Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: vincent-gcc at vinc17 dot net Target Milestone: --- Consider #include void f (int *); void g (void) { int e; char s[4]; f (&e); sprintf (s, "%d", e); sprintf (s, "%d", e - 1); } I get on my Linux/x86_64 machine with gcc-12 (Debian 12.2.0-14) 12.2.0: zira:~> gcc-12 -Wformat-overflow -c tst.c tst.c: In function =E2=80=98g=E2=80=99: tst.c:12:16: warning: =E2=80=98%d=E2=80=99 directive writing between 1 and = 11 bytes into a region of size 4 [-Wformat-overflow=3D] 12 | sprintf (s, "%d", e - 1); | ^~ tst.c:12:15: note: directive argument in the range [-2147483648, 2147483646] 12 | sprintf (s, "%d", e - 1); | ^~~~ tst.c:12:3: note: =E2=80=98sprintf=E2=80=99 output between 2 and 12 bytes i= nto a destination of size 4 12 | sprintf (s, "%d", e - 1); | ^~~~~~~~~~~~~~~~~~~~~~~~ Note that the warning occurs for "e - 1" but not for "e". This bug was found when compiling GNU MPFR 4.2.0 with "-std=3Dc90 -Werror= =3Dformat -m32" (compilation failure for get_d64.c).=