public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/111513] New: Incorrect -Wformat-overflow warning when using UBSAN with gettext()
@ 2023-09-21  6:48 gcc@t-8ch.de
  2023-09-21  6:53 ` [Bug sanitizer/111513] " gcc@t-8ch.de
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: gcc@t-8ch.de @ 2023-09-21  6:48 UTC (permalink / raw)
  To: gcc-bugs

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: 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, 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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-09-21  7:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-21  6:48 [Bug sanitizer/111513] New: Incorrect -Wformat-overflow warning when using UBSAN with gettext() gcc@t-8ch.de
2023-09-21  6:53 ` [Bug sanitizer/111513] " gcc@t-8ch.de
2023-09-21  7:15 ` [Bug tree-optimization/111513] " pinskia at gcc dot gnu.org
2023-09-21  7:20 ` pinskia at gcc dot gnu.org
2023-09-21  7:39 ` gcc@t-8ch.de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).