Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incorrect specifier in format string #140

Open
raenye opened this issue Oct 19, 2023 · 0 comments
Open

incorrect specifier in format string #140

raenye opened this issue Oct 19, 2023 · 0 comments

Comments

@raenye
Copy link

raenye commented Oct 19, 2023

ADD2LOG("libhd version %s%s (%s) [%ld]\n", HD_VERSION_STRING, getuid() ? "u" : "", HD_ARCH, sizeof (hd_data_t));

sizeof returns size_t, so %zu should be used instead of %lu.

This may sound insignificant, but on some platforms size_t is unsigned int, and this is different from unsigned long.

make[4]: Entering directory '/home/user/git/openwrt/build_dir/target-mipsel_24kc_musl/hwinfo-21.71'
make[5]: Entering directory '/home/user/git/openwrt/build_dir/target-mipsel_24kc_musl/hwinfo-21.71/src'
make[6]: Entering directory '/home/user/git/openwrt/build_dir/target-mipsel_24kc_musl/hwinfo-21.71/src/hd'
mipsel-openwrt-linux-musl-gcc -c -Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -msoft-float -fmacro-prefix-map=/home/user/git/openwrt/build_dir/target-mipsel_24kc_musl/hwinfo-21.71=hwinfo-21.71 -mips16 -minterlink-mips16 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro  -I/home/user/git/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-12.3.0_musl/usr/include -I/home/user/git/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-12.3.0_musl/include/fortify -I/home/user/git/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-12.3.0_musl/include  -Wall -Wno-pointer-sign   -I/home/user/git/openwrt/build_dir/target-mipsel_24kc_musl/hwinfo-21.71/src/hd -Wall -Wno-pointer-sign -fPIC  -I../src/hd -Wall -Wno-pointer-sign -fPIC  -I../../src/hd  -L/home/user/git/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-12.3.0_musl/usr/lib -L/home/user/git/openwrt/staging_dir/toolchain-mipsel_24kc_gcc-12.3.0_musl/lib -fuse-ld=bfd -znow -zrelro  -Lsrc -Lsrc -Lsrc hd.c
In file included from hd.c:61:
hd.c: In function 'hd_scan':
hd.c:1823:15: warning: format '%ld' expects argument of type 'long int', but argument 6 has type 'unsigned int' [-Wformat=]
 1823 |       ADD2LOG("libhd version %s%s (%s) [%ld]\n", HD_VERSION_STRING, getuid() ? "u" : "", HD_ARCH, sizeof (hd_data_t));
      |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                   ~~~~~~~~~~~~~~~~~~
      |                                                                                                   |
      |                                                                                                   unsigned int
hd_int.h:66:46: note: in definition of macro 'ADD2LOG'
   66 | #define ADD2LOG(a...) hd_log_printf(hd_data, a)
      |                                              ^
hd.c:1823:43: note: format string is defined here
 1823 |       ADD2LOG("libhd version %s%s (%s) [%ld]\n", HD_VERSION_STRING, getuid() ? "u" : "", HD_ARCH, sizeof (hd_data_t));
      |                                         ~~^
      |                                           |
      |                                           long int
      |                                         %d
mipsel-openwrt-linux-musl-gcc-ar r ../../src/libhd.a hd.o
make[6]: Leaving directory '/home/user/git/openwrt/build_dir/target-mipsel_24kc_musl/hwinfo-21.71/src/hd'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant