https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96739
Bug ID: 96739 Summary: attribute(constructor) vs format NULL check Product: gcc Version: 10.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: dgilbert at redhat dot com Target Milestone: --- Created attachment 49096 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49096&action=edit boiled down test file The following is boiled down (too far?) from current (d6f83a72a7db94a3ede9f5cc4fb39f9c8e89f954) qemu-io-cmds.c and generates the warning: ioprob.c:28:5: warning: ‘%s’ directive argument is null [-Wformat-overflow=] 28 | printf("%s ", ct->name); | ^~~~~~~~~~~~~~~~~~~~~~~ unless the __attribute((constructor)) is removed from init_qemuio_commands I think the problem here is that ct comes from cmdtab which is a static and it doesn't notice that it's initialised, and therefore decides it's NULL? cc -O1 -Wformat -Wformat-security -c ioprob.c -Wunused In function ‘help_oneline’, inlined from ‘help_all’ at ioprob.c:34:5, inlined from ‘help_f’ at ioprob.c:39:5: ioprob.c:28:5: warning: ‘%s’ directive argument is null [-Wformat-overflow=] 28 | printf("%s ", ct->name); | ^~~~~~~~~~~~~~~~~~~~~~~ [dgilbert@dgilbert-t580 try]$ gcc -v Using built-in specs. COLLECT_GCC=/usr/bin/gcc COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/10/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --enable-offload-targets=nvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 10.2.1 20200723 (Red Hat 10.2.1-1) (GCC)