This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/59125] New: [4.8 regression] gcc triggers wrong strncpy_chk
- From: "jengelh at inai dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 14 Nov 2013 01:23:57 +0000
- Subject: [Bug c/59125] New: [4.8 regression] gcc triggers wrong strncpy_chk
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59125
Bug ID: 59125
Summary: [4.8 regression] gcc triggers wrong strncpy_chk
Product: gcc
Version: 4.8.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: jengelh at inai dot de
Given this compiler version/variant:
> gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/4.8/lto-wrapper
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info
--mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64
--enable-languages=c,c++,objc,fortran,obj-c++,java,ada
--enable-checking=release --with-gxx-include-dir=/usr/include/c++/4.8
--enable-ssp --disable-libssp --disable-plugin
--with-bugurl=http://bugs.opensuse.org/ --with-pkgversion='SUSE Linux'
--disable-libgcj --disable-libmudflap --with-slibdir=/lib64 --with-system-zlib
--enable-__cxa_atexit --enable-libstdcxx-allocator=new --disable-libstdcxx-pch
--enable-version-specific-runtime-libs --enable-linker-build-id
--enable-linux-futex --program-suffix=-4.8 --without-system-libunwind
--with-arch-32=i586 --with-tune=generic --build=x86_64-suse-linux
--host=x86_64-suse-linux
Thread model: posix
gcc version 4.8.2 20131016 [gcc-4_8-branch revision 203692] (SUSE Linux)
and this source:
#include <string.h>
union u {
struct {
char vi[8];
char pi[16];
};
char all[8+16+4];
};
void f(union u *u)
{
char vi[8+1];
char pi[16+1];
strncpy(vi, u->vi, sizeof(u->vi));
strncpy(pi, u->pi, sizeof(u->pi));
strncpy(u->all, "AbcdefghAbcdefghijklmnopAbcd", sizeof(u->all));
}
I observe:
$ gcc-4.8 -O2 -D_FORTIFY_SOURCE=2 -c test.c
In file included from /usr/include/string.h:638:0,
from sci.c:1:
In function âstrncpyâ,
inlined from âfâ at sci.c:15:9:
/usr/include/bits/string3.h:120:3: warning: call to __builtin___strncpy_chk
will always overflow destination buffer [enabled by default]
return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
^
$ gcc-4.7 -O2 -D_FORTIFY_SOURCE=2 -c sci.c
$ clang -O2 -D_FORTIFY_SOURCE=2 -c sci.c
I would have expected:
gcc-4.8 to do as gcc-4.7 did and remain silent. I cannot see anything wrong
with the strncpy linesâ