public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/113414] New: Incorrent checking for printf format: does not distinguish whether the variable is signed or unsigned
@ 2024-01-16 4:24 tongxiangzheng.route at gmail dot com
2024-01-16 4:42 ` [Bug c/113414] " pinskia at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: tongxiangzheng.route at gmail dot com @ 2024-01-16 4:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113414
Bug ID: 113414
Summary: Incorrent checking for printf format: does not
distinguish whether the variable is signed or unsigned
Product: gcc
Version: 11.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: tongxiangzheng.route at gmail dot com
Target Milestone: ---
When checking the printf() function, gcc does not distinguish whether the
variable is signed or unsigned.
for example:
$ gcc test.cpp
#include<stdio.h>
int main(){
int n;
printf("%u",n);
}
The code should be warned, but it did not.
example 2:
$ gcc test.cpp
#include<stdio.h>
int main(){
unsigned long long int n;
printf("%d",n);
}
The code be warned, but it's wrong:
test.cpp: In function ‘int main()’:
test.cpp:4:18: warning: format ‘%d’ expects argument of type ‘int’, but
argument 2 has type ‘long long unsigned int’ [-Wformat=]
4 | printf("%d",n);
| ~^ ~
| | |
| | long long unsigned int
| int
| %lld
gcc suggests using %lld, but in reality, %llu should be used.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/113414] Incorrent checking for printf format: does not distinguish whether the variable is signed or unsigned
2024-01-16 4:24 [Bug c/113414] New: Incorrent checking for printf format: does not distinguish whether the variable is signed or unsigned tongxiangzheng.route at gmail dot com
@ 2024-01-16 4:42 ` pinskia at gcc dot gnu.org
2024-01-16 4:44 ` pinskia at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-16 4:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113414
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>The code should be warned, but it did not.
No that is by design. You need to use -Wformat-signedness for that.
But for the second example, the fix it note is wrong only with
-Wformat-signedness .
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/113414] Incorrent checking for printf format: does not distinguish whether the variable is signed or unsigned
2024-01-16 4:24 [Bug c/113414] New: Incorrent checking for printf format: does not distinguish whether the variable is signed or unsigned tongxiangzheng.route at gmail dot com
2024-01-16 4:42 ` [Bug c/113414] " pinskia at gcc dot gnu.org
@ 2024-01-16 4:44 ` pinskia at gcc dot gnu.org
2024-01-16 5:04 ` xry111 at gcc dot gnu.org
2024-01-16 5:42 ` egallager at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-16 4:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113414
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
See Also| |https://gcc.gnu.org/bugzill
| |a/show_bug.cgi?id=90205
Status|UNCONFIRMED |RESOLVED
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> >The code should be warned, but it did not.
>
>
> No that is by design. You need to use -Wformat-signedness for that.
>
> But for the second example, the fix it note is wrong only with
> -Wformat-signedness .
But that is already PR 90205 .
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/113414] Incorrent checking for printf format: does not distinguish whether the variable is signed or unsigned
2024-01-16 4:24 [Bug c/113414] New: Incorrent checking for printf format: does not distinguish whether the variable is signed or unsigned tongxiangzheng.route at gmail dot com
2024-01-16 4:42 ` [Bug c/113414] " pinskia at gcc dot gnu.org
2024-01-16 4:44 ` pinskia at gcc dot gnu.org
@ 2024-01-16 5:04 ` xry111 at gcc dot gnu.org
2024-01-16 5:42 ` egallager at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: xry111 at gcc dot gnu.org @ 2024-01-16 5:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113414
Xi Ruoyao <xry111 at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |xry111 at gcc dot gnu.org
--- Comment #3 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
And IMO it's not really "wrong" to suggest %lld. Using %lld may not be what
you really want, but it's at least allowed by the standard (while using %d here
is prohibited and leading to an undefined behavior).
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/113414] Incorrent checking for printf format: does not distinguish whether the variable is signed or unsigned
2024-01-16 4:24 [Bug c/113414] New: Incorrent checking for printf format: does not distinguish whether the variable is signed or unsigned tongxiangzheng.route at gmail dot com
` (2 preceding siblings ...)
2024-01-16 5:04 ` xry111 at gcc dot gnu.org
@ 2024-01-16 5:42 ` egallager at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: egallager at gcc dot gnu.org @ 2024-01-16 5:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113414
Eric Gallager <egallager at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |egallager at gcc dot gnu.org
Keywords| |diagnostic
--- Comment #4 from Eric Gallager <egallager at gcc dot gnu.org> ---
I forget which other bug I mentioned this in, but this reminds me that I still
think a -Wformat=3 that includes -Wformat-signedness would be nice, as
currently it only goes up to -Wformat=2, which doesn't include
-Wformat-signedness currently.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-01-16 5:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 4:24 [Bug c/113414] New: Incorrent checking for printf format: does not distinguish whether the variable is signed or unsigned tongxiangzheng.route at gmail dot com
2024-01-16 4:42 ` [Bug c/113414] " pinskia at gcc dot gnu.org
2024-01-16 4:44 ` pinskia at gcc dot gnu.org
2024-01-16 5:04 ` xry111 at gcc dot gnu.org
2024-01-16 5:42 ` egallager 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).