public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "vincent-gcc at vinc17 dot net" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-109979-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109979 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 <stdio.h> 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 ‘g’: tst.c:12:16: warning: ‘%d’ directive writing between 1 and 11 bytes into a region of size 4 [-Wformat-overflow=] 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: ‘sprintf’ output between 2 and 12 bytes into 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=c90 -Werror=format -m32" (compilation failure for get_d64.c).
next reply other threads:[~2023-05-26 7:17 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-05-26 7:17 vincent-gcc at vinc17 dot net [this message] 2023-05-26 7:19 ` [Bug c/109979] " pinskia at gcc dot gnu.org 2023-05-26 7:23 ` [Bug c/109979] " pinskia at gcc dot gnu.org 2023-05-26 7:28 ` pinskia at gcc dot gnu.org 2023-05-26 7:39 ` rguenth at gcc dot gnu.org 2023-05-26 7:54 ` vincent-gcc at vinc17 dot net
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-109979-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: linkBe 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).