Closed geotro closed 5 days ago
Seconded: I have the same issue, I think.
(Running on MX Linux 23.3, fully updated; gcc (Debian 12.2.0-14) 12.2.0)
lproven@thinkpad-t420-i7:~/0xtools$ make
cc -Wall -I include -o bin/xcapture src/xcapture.c
src/xcapture.c: In function ‘main’:
src/xcapture.c:404:28: warning: ‘%03d’ directive writing between 3 and 8 bytes into a region of size 6 [-Wformat-overflow=]
404 | sprintf(usec_buf, "%03d", (int)tmnow.tv_usec/1000); // ms resolution should be ok for infrequent sampling
| ^~~~
src/xcapture.c:404:27: note: directive argument in the range [-2147483, 2147483]
404 | sprintf(usec_buf, "%03d", (int)tmnow.tv_usec/1000); // ms resolution should be ok for infrequent sampling
| ^~~~~~
src/xcapture.c:404:9: note: ‘sprintf’ output between 4 and 9 bytes into a destination of size 6
404 | sprintf(usec_buf, "%03d", (int)tmnow.tv_usec/1000); // ms resolution should be ok for infrequent sampling
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Yes I noticed these warnings when I compiled the (/proc-sampling) xcapture v1 on a newer distro with a newer gcc (gcc on Ubuntu 24.04 gives the the warning, on 22.04 or RHEL8/9 I didn't see it). These are warnings, the make/compile still succeeds.
I'll take a look and improve this.
$ make cc -Wall -I include -o bin/xcapture src/xcapture.c src/xcapture.c: In function ‘main’: src/xcapture.c:404:28: warning: ‘%03d’ directive writing between 3 and 8 bytes into a region of size 6 [-Wformat-overflow=] 404 | sprintf(usec_buf, "%03d", (int)tmnow.tv_usec/1000); // ms resolution should be ok for infrequent sampling | ^~~~ src/xcapture.c:404:27: note: directive argument in the range [-2147483, 2147483] 404 | sprintf(usec_buf, "%03d", (int)tmnow.tv_usec/1000); // ms resolution should be ok for infrequent sampling | ^
~src/xcapture.c:404:9: note: ‘sprintf’ output between 4 and 9 bytes into a destination of size 6 404 | sprintf(usec_buf, "%03d", (int)tmnow.tv_usec/1000); // ms resolution should be ok for infrequent sampling | ^~~~~~~~~~~~~~$ cc --version cc (Ubuntu 13.2.0-23ubuntu4) 13.2.0 Copyright (C) 2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Looking forward to trying these tools out!