public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/114430] New: False positive for -Wformat
@ 2024-03-22  7:07 admin@tho-otto.de
  0 siblings, 0 replies; only message in thread
From: admin@tho-otto.de @ 2024-03-22  7:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114430

            Bug ID: 114430
           Summary: False positive for -Wformat
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: admin@tho-otto.de
  Target Milestone: ---

Using GCC 13.2.1, with:


#include <stdio.h>

struct WWPerson
{
    char Name[12];
};

struct WWPerson WWPersons[] = {
    {"Bill R"},
    {"Bill R"},
    {"Barry G"},
};

char item[12 + 1];
void test()
{
    for (size_t i = 0; i < sizeof(WWPersons) / sizeof(struct WWPerson); i++) {
        sprintf(item, "%s", WWPersons[i].Name);
        }
}


When compiling with -O2, i get:

bla.c: In function ‘test’:
bla.c:18:24: warning: ‘%s’ directive writing up to 35 bytes into a region of
size 13 [-Wformat-overflow=]
   18 |         sprintf(item, "%s", WWPersons[i].Name);
      |                        ^~
bla.c:18:9: note: ‘sprintf’ output between 1 and 36 bytes into a destination of
size 13
   18 |         sprintf(item, "%s", WWPersons[i].Name);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I get the same warning with version 10.5.0, but not with version 9.5.0

The warning disappears when i remove one element from the array.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-03-22  7:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-22  7:07 [Bug c/114430] New: False positive for -Wformat admin@tho-otto.de

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