https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111513
Bug ID: 111513 Summary: Incorrect -Wformat-overflow warning when using UBSAN with gettext() Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: g...@t-8ch.de CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org, jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, marxin at gcc dot gnu.org Target Milestone: --- Created attachment 55957 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55957&action=edit preprocessed source The test program below exhibits the following compiler warning: test.c: In function ‘main’: test.c:14:9: warning: null format string [-Wformat-overflow=] 14 | printf(gettext("foo %s\n"), "foo"); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test.c:14:9: warning: null format string [-Wformat-overflow=] /* test.c * * compile with: * gcc -Wall -fsanitize=undefined -O2 test.c */ #include <stdio.h> #include <libintl.h> int main(void) { FILE *out = stdout; fputs("\n", out); printf(gettext("foo %s\n"), "foo"); fputs("\n", out); } The warning can be "fixed" by *any* of the following steps: * remove any of the fputs() calls * inline the stdout parameter into the second fputs() call * build without optimizations * build without UBSAN Given the weirdness with regards to the fputs() calls I suspect the issue in GCC. $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --enable-languages=ada,c,c++,d,fortran,go,lto,objc,obj-c++ --enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --with-build-config=bootstrap-lto --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-cet=auto --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-libstdcxx-backtrace --enable-link-serialization=1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-werror Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 13.2.1 20230801 (GCC) glibc version: 2.38