public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/108518] New: Format-overflow warning using `*.s` directive with null but zero-length string
@ 2023-01-24 14:01 aaron at aarongraham dot com
2023-01-24 21:16 ` [Bug c/108518] " pinskia at gcc dot gnu.org
2023-01-24 21:19 ` pinskia at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: aaron at aarongraham dot com @ 2023-01-24 14:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108518
Bug ID: 108518
Summary: Format-overflow warning using `*.s` directive with
null but zero-length string
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: aaron at aarongraham dot com
Target Milestone: ---
https://godbolt.org/z/YGra91Woa
#include <stdio.h>
int main() {
// This causes a format-overflow warning, but it
// should not warn if size() is 0
printf("%.*s\n", 0, (char*)0);
}
The warning is:
<source>: In function 'int main()':
<source>:6:13: warning: '%.*s' directive argument is null [-Wformat-overflow=]
6 | printf("%.*s\n", 0, (char*)0);
| ^~~~
I see this commonly when using std::string_view with printf. In cases where it
knows that you're passing a default-constructed string_view it produces this
warning.
It should not produce this warning if the length being printed is 0.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/108518] Format-overflow warning using `*.s` directive with null but zero-length string
2023-01-24 14:01 [Bug c/108518] New: Format-overflow warning using `*.s` directive with null but zero-length string aaron at aarongraham dot com
@ 2023-01-24 21:16 ` pinskia at gcc dot gnu.org
2023-01-24 21:19 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-24 21:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108518
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I think it is still undefined if the argument is null even if the length of 0
is supplied from my reading of the standard:
If no l length modifier is present, the argument shall be a pointer to the
initial element of an array of character type.
If the precision is specified, no more than that many bytes are written.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/108518] Format-overflow warning using `*.s` directive with null but zero-length string
2023-01-24 14:01 [Bug c/108518] New: Format-overflow warning using `*.s` directive with null but zero-length string aaron at aarongraham dot com
2023-01-24 21:16 ` [Bug c/108518] " pinskia at gcc dot gnu.org
@ 2023-01-24 21:19 ` pinskia at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-01-24 21:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108518
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
In similar fashion memcpy/memset with a size argument of 0 passed, they have to
be a non-null pointer.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-01-24 21:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-24 14:01 [Bug c/108518] New: Format-overflow warning using `*.s` directive with null but zero-length string aaron at aarongraham dot com
2023-01-24 21:16 ` [Bug c/108518] " pinskia at gcc dot gnu.org
2023-01-24 21:19 ` pinskia 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).