This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GCC 4.9.2 -O3 gives a seg fault / GCC 4.8.2 -O3 works


On Tue, 2015-01-06 at 09:43 +0100, Jakub Jelinek wrote:
> GCC trunk -fsanitize=undefined (in particular
> -fsanitize=nonnull-attribute)
> diagnoses it:
> /tmp/mystring.cpp:103:26: runtime error: null pointer passed as
> argument 2, which is declared to never be null

Unfortunately adding -fsanitize=undefined in GCC 4.9.2 doesn't notice
this (in fact it actually causes the segfault to go away).

I can try to build a trunk version for this test, I suppose.

> LD_PRELOAD=libmemstomp.so detects it too.
> 
> Calling memcpy (p, NULL, 0); is invalid according to C and C++
> standards, you need to guard it, e.g. with if (data) memcpy (p, data,
> len1);
> or if (len1) memcpy (p, data, len1);

I'm on a Debian-based system and can't find a memstomp package so I
grabbed git://fedorapeople.org/home/fedora/wcohen/public_git/memstomp
and built it myself, but for some reason it doesn't fire in my
environment:

$ LD_PRELOAD=/home/psmith/src/memstomp/.libs/libmemstomp.so ./tst
memstomp: 0.1.4 sucessfully initialized for process tst (pid 26438).
Segmentation fault (core dumped)

Even if I rebuild without -O3 it passes with no warnings.  My GCC
installation uses --sysroot to build against an older glibc, etc. so
maybe that's causing some sort of issue...

Seems like I have some work to do here to come up with a way to detect
other failure situations like this.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]