openSUSE / hwinfo

Hardware information tool
GNU General Public License v2.0
256 stars 69 forks source link

incorrect specifier in format string #140

Open raenye opened 11 months ago

raenye commented 11 months ago

https://github.com/openSUSE/hwinfo/blob/c87f449f1d4882c71b0a1e6dc80638224a5baeed/src/hd/hd.c#L1824

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'