public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/100401] New: Bogus -Wformat-overflow warning
@ 2021-05-03 16:58 lavr at ncbi dot nlm.nih.gov
  2021-05-03 19:30 ` [Bug middle-end/100401] Bogus -Wformat-overflow for a trailing zero-length array of a union msebor at gcc dot gnu.org
  2021-05-03 20:09 ` lavr at ncbi dot nlm.nih.gov
  0 siblings, 2 replies; 3+ messages in thread
From: lavr at ncbi dot nlm.nih.gov @ 2021-05-03 16:58 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 100401
           Summary: Bogus -Wformat-overflow warning
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lavr at ncbi dot nlm.nih.gov
  Target Milestone: ---

$ gcc --version
gcc (GCC) 10.2.0


$ cat bogus.c
#include <stdio.h>

#define RECLEN  128

struct S {
    int  code;
    char text[0];
};


const void fun(int n)
{
    union {
        struct S s;
        char     rec[RECLEN];
    } x;
    const char* err;

    if (!n) {
        err = "No error";
    } else {
        sprintf(x.s.text, "Error %d", n);
        err = x.s.text;
    }
    printf("%s\n", err);
}


int main(int argc, const char* argv[])
{
    fun(argc);
    return 0;
}


$ gcc -Wall -O2 bogus.c
bogus.c: In function ‘fun’:
bogus.c:22:28: warning: ‘Error ’ directive writing 6 bytes into a region of
size 0 [-Wformat-overflow=]
   22 |         sprintf(x.s.text, "Error %d", n);
      |                            ^~~~~~
bogus.c:22:9: note: ‘sprintf’ output between 8 and 18 bytes into a destination
of size 0
   22 |         sprintf(x.s.text, "Error %d", n);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

end of thread, other threads:[~2021-05-03 20:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-03 16:58 [Bug c/100401] New: Bogus -Wformat-overflow warning lavr at ncbi dot nlm.nih.gov
2021-05-03 19:30 ` [Bug middle-end/100401] Bogus -Wformat-overflow for a trailing zero-length array of a union msebor at gcc dot gnu.org
2021-05-03 20:09 ` lavr at ncbi dot nlm.nih.gov

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