public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/115513] New: attribute nonstring could help with printf mistakes
@ 2024-06-16 17:32 peter at eisentraut dot org
  2024-06-17  2:09 ` [Bug c/115513] " xry111 at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: peter at eisentraut dot org @ 2024-06-16 17:32 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115513
           Summary: attribute nonstring could help with printf mistakes
           Product: gcc
           Version: 14.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: peter at eisentraut dot org
  Target Milestone: ---

Created attachment 58446
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58446&action=edit
test file

Consider this test program (also attached):

```
#include <stdio.h>
#include <string.h>

struct Data
{
        char name[32] __attribute__((nonstring));
};

int f (struct Data *pd, const char *s)
{
        strncpy(pd->name, s, sizeof pd->name);

        printf("%s", pd->name);  // unsafe, no warning!?!

        return strlen(pd->name);   // unsafe, gets a warning
}
```

Compile with, e.g.: gcc-14 -c -Wall -Wextra -O2 test.c

As per the documentation, this will warn about the strlen() call.

But it doesn't warn about the printf() call.  This would be quite useful and
seems to be a gap in the warning coverage of this attribute.

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

end of thread, other threads:[~2024-06-17 11:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-16 17:32 [Bug c/115513] New: attribute nonstring could help with printf mistakes peter at eisentraut dot org
2024-06-17  2:09 ` [Bug c/115513] " xry111 at gcc dot gnu.org
2024-06-17  9:59 ` peter at eisentraut dot org
2024-06-17 11:07 ` xry111 at gcc dot gnu.org

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