From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 755E03858402; Wed, 15 Sep 2021 01:04:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 755E03858402 From: "rootkit85 at yahoo dot it" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/102337] New: possibly wrong warning about truncation Date: Wed, 15 Sep 2021 01:04:19 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 11.2.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rootkit85 at yahoo dot it 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 target_milestone 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Sep 2021 01:04:19 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102337 Bug ID: 102337 Summary: possibly wrong warning about truncation Product: gcc Version: 11.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: rootkit85 at yahoo dot it Target Milestone: --- The following code: #include // build with: -O2 -Werror=3Dformat-truncation void poke_kprobe_events(int add) { char cmd[192], probename[128], probefunc[128]; snprintf(probename, sizeof(probename), "a"); snprintf(probefunc, sizeof(probefunc), "b"); snprintf(cmd, sizeof(cmd), "%s %s", probename, probefunc); } Generates the following warning: $ gcc -O2 -c test.c -Werror=3Dformat-truncation test.c: In function =E2=80=98poke_kprobe_events=E2=80=99: test.c:11:40: error: =E2=80=98%s=E2=80=99 directive output may be truncated= writing up to 127 bytes into a region of size between 64 and 191 [-Werror=3Dformat-truncation= =3D] 11 | snprintf(cmd, sizeof(cmd), "%s %s", probename, probefunc); | ^~ ~~~~~~~~~ test.c:11:9: note: =E2=80=98snprintf=E2=80=99 output between 2 and 256 byte= s into a destination of size 192 11 | snprintf(cmd, sizeof(cmd), "%s %s", probename, probefunc); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cc1: some warnings being treated as errors I'm using the Fedora 34 packages: $ gcc -v Using built-in specs. COLLECT_GCC=3Dgcc COLLECT_LTO_WRAPPER=3D/usr/libexec/gcc/x86_64-redhat-linux/11/lto-wrapper OFFLOAD_TARGET_NAMES=3Dnvptx-none OFFLOAD_TARGET_DEFAULT=3D1 Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=3Dc,c++,fortran,objc,obj-c++,ada,go,d,lto --prefix=3D/usr --mandir=3D/usr/share/man --infodir=3D/usr/share/info --with-bugurl=3Dhttp://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=3Dposix --enable-checking=3Drelease --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=3Dgnu --enable-plugin --enable-initfini-array --with-isl=3D/builddir/build/BUILD/gcc-11.2.1-20210728/obj-x86_64-redhat-li= nux/isl-install --enable-offload-targets=3Dnvptx-none --without-cuda-driver --enable-gnu-indirect-function --enable-cet --with-tune=3Dgeneric --with-arch_32=3Di686 --build=3Dx86_64-redhat-linux Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.2.1 20210728 (Red Hat 11.2.1-1) (GCC)=