https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124231
Bug ID: 124231
Summary: No format warning for specifier "%d" (or "%x") with
long unsigned int argument
Product: gcc
Version: 13.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: peter.barada at gmail dot com
Target Milestone: ---
Created attachment 63780
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63780&action=edit
Testcase that doesn't show format warning - until linemarkers are removed
System: x86_64 Ubuntu 24.0.4 LTS
Compiler: x86_64 gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
Testcase: testcase.c (attached)
Command: gcc -Wformat -c /tmp/testcase.c
Compiling the attached preprocessed testcase.c does _not_ generate a format
warning while using "%d" (or "%x") format specifier with a long unsigned int
typed argument.
_However_ if I remove linemarker line content generated by C preprocessor (via
"sed -ie 's/^#.*$//' /tmp/testcase.c") and recompile using same command
(causing line endings to stay at same offset) and recompile (using same "gcc
-Wformat /tmp/testcase.c") gcc generates format warnings:
/tmp/testcase.c: In function ‘stm32_getreg’:
/tmp/testcase.c:52:20: warning: format ‘%d’ expects argument of type ‘int’, but
argument 4 has type ‘uint32_t’ {aka ‘long unsigned int’} [-Wformat=]
52 | syslog(6, "%s: "
| ^~~~~~
......
58 | count - 3
| ~~~~~~~~~
| |
| uint32_t {aka long unsigned int}
/tmp/testcase.c:54:21: note: format string is defined here
54 | "[repeats %d more times]\n"
| ~^
| |
| int
| %ld
/tmp/testcase.c:76:12: warning: format ‘%x’ expects argument of type ‘unsigned
int’, but argument 4 has type ‘uint32_t’ {aka ‘long unsigned int’} [-Wformat=]
76 | syslog(6, "%s: "
| ^~~~~~
......
82 | addr, val
| ~~~~
| |
| uint32_t {aka long unsigned int}
/tmp/testcase.c:78:6: note: format string is defined here
78 | "%08x->%08x\n"
| ~~~^
| |
| unsigned int
| %08lx
/tmp/testcase.c:76:12: warning: format ‘%x’ expects argument of type ‘unsigned
int’, but argument 5 has type ‘uint32_t’ {aka ‘long unsigned int’} [-Wformat=]
76 | syslog(6, "%s: "
| ^~~~~~
......
82 | addr, val
| ~~~
| |
| uint32_t {aka long unsigned int}
/tmp/testcase.c:78:12: note: format string is defined here
78 | "%08x->%08x\n"
| ~~~^
| |
| unsigned int
| %08lx