public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/109979] New: [12 Regression] -Wformat-overflow false positive for %d and non-basic expression
@ 2023-05-26  7:17 vincent-gcc at vinc17 dot net
  2023-05-26  7:19 ` [Bug c/109979] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: vincent-gcc at vinc17 dot net @ 2023-05-26  7:17 UTC (permalink / raw)
  To: gcc-bugs

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).

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-05-26  7:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-26  7:17 [Bug c/109979] New: [12 Regression] -Wformat-overflow false positive for %d and non-basic expression vincent-gcc at vinc17 dot net
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

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).