public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug analyzer/114920] New: null_terminated_string_arg attribute does not warn for non-nul-terminated strings
@ 2024-05-02 10:02 bruno at clisp dot org
2024-05-02 18:31 ` [Bug analyzer/114920] " dmalcolm at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: bruno at clisp dot org @ 2024-05-02 10:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114920
Bug ID: 114920
Summary: null_terminated_string_arg attribute does not warn for
non-nul-terminated strings
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: analyzer
Assignee: dmalcolm at gcc dot gnu.org
Reporter: bruno at clisp dot org
Target Milestone: ---
Created attachment 58085
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58085&action=edit
test case foo.c
The documentation of null_terminated_string_arg in
https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html gave me the
expectation that the analyzer would produce a warning when I pass a
non-NUL-terminated string to a function declared with this attribute. But it
doesn't, neither for stack-allocated strings nor for heap-allocated strings.
Test case:
============================= foo.c ===========================
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
extern size_t strlen (const char *s) __attribute__
((__null_terminated_string_arg__ (1)));
int main ()
{
{
char s[7];
memcpy (s, "FOOBAR!", 7);
printf ("n=%d\n", (int) strlen (s));
}
{
char *s = malloc (7);
if (s != NULL) {
memcpy (s, "FOOBAR!", 7);
printf ("n=%d\n", (int) strlen (s));
}
}
}
===============================================================
$ gcc -c foo.c -Wall -Wextra -fanalyzer -Wanalyzer-use-of-uninitialized-value
-Wanalyzer-out-of-bounds
Expected: two warnings
Actual: no warning.
$ gcc --version
gcc (GCC) 14.0.1 20240411 (Red Hat 14.0.1-0)
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug analyzer/114920] null_terminated_string_arg attribute does not warn for non-nul-terminated strings
2024-05-02 10:02 [Bug analyzer/114920] New: null_terminated_string_arg attribute does not warn for non-nul-terminated strings bruno at clisp dot org
@ 2024-05-02 18:31 ` dmalcolm at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: dmalcolm at gcc dot gnu.org @ 2024-05-02 18:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114920
David Malcolm <dmalcolm at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2024-05-02
--- Comment #1 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
Thanks for filing this bug report.
Confirmed with trunk; see e.g.:
https://godbolt.org/z/5x5fqe4Td
I'm taking a look.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-05-02 18:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-02 10:02 [Bug analyzer/114920] New: null_terminated_string_arg attribute does not warn for non-nul-terminated strings bruno at clisp dot org
2024-05-02 18:31 ` [Bug analyzer/114920] " dmalcolm 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).