From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id ABE693858C52; Thu, 21 Sep 2023 06:48:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ABE693858C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695278895; bh=qUejoHNPUiIyLYcId8mWSaH4Ug6UgiArZoOBjpg75EQ=; h=From:To:Subject:Date:From; b=BJYyVUVqITPA1TinKBvzcz9da8z8mtTzr29IPq8b14ixhkgPGx2tFRtF8HgE2UvwV SxzvG2QNemjVBMbzts2jpCO9q7w0wr253fhz8LsPKOWsT+FpFf8rGBZ91WnbuBuo8Y 4ddl1WWYLzFbw28cbBMYvqIUHjiAOMNrNSSXWNQM= From: "gcc@t-8ch.de" To: gcc-bugs@gcc.gnu.org Subject: [Bug sanitizer/111513] New: Incorrect -Wformat-overflow warning when using UBSAN with gettext() Date: Thu, 21 Sep 2023 06:48:15 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: sanitizer X-Bugzilla-Version: 13.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gcc@t-8ch.de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D111513 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: gcc@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, marxi= n at gcc dot gnu.org Target Milestone: --- Created attachment 55957 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D55957&action=3Dedit preprocessed source The test program below exhibits the following compiler warning: test.c: In function =E2=80=98main=E2=80=99: test.c:14:9: warning: null format string [-Wformat-overflow=3D] 14 | printf(gettext("foo %s\n"), "foo"); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ test.c:14:9: warning: null format string [-Wformat-overflow=3D] /* test.c * * compile with: * gcc -Wall -fsanitize=3Dundefined -O2 test.c */ #include #include int main(void) { FILE *out =3D 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=3Dgcc COLLECT_LTO_WRAPPER=3D/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=3Dada,c,c++,d,fortran,go,lto,objc,obj-c++ --enable-boots= trap --prefix=3D/usr --libdir=3D/usr/lib --libexecdir=3D/usr/lib --mandir=3D/usr= /share/man --infodir=3D/usr/share/info --with-bugurl=3Dhttps://bugs.archlinux.org/ --with-build-config=3Dbootstrap-lto --with-linker-hash-style=3Dgnu --with-system-zlib --enable-__cxa_atexit --enable-cet=3Dauto --enable-checking=3Drelease --enable-clocale=3Dgnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-obj= ect --enable-libstdcxx-backtrace --enable-link-serialization=3D1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=3Dposix --disable-libssp --disable-libstdc= xx-pch --disable-werror Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 13.2.1 20230801 (GCC)=20 glibc version: 2.38=