This is the mail archive of the
mailing list for the GCC project.
Re: GCC 4.9.2 -O3 gives a seg fault / GCC 4.8.2 -O3 works
- From: Paul Smith <paul at mad-scientist dot net>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 06 Jan 2015 11:28:52 -0500
- Subject: Re: GCC 4.9.2 -O3 gives a seg fault / GCC 4.8.2 -O3 works
- Authentication-results: sourceware.org; auth=none
- References: <1420532328 dot 7095 dot 263 dot camel at homebase> <20150106084350 dot GE1667 at tucnak dot redhat dot com>
On Tue, 2015-01-06 at 09:43 +0100, Jakub Jelinek wrote:
> GCC trunk -fsanitize=undefined (in particular
> 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,
> or if (len1) memcpy (p, data, len1);
I'm on a Debian-based system and can't find a memstomp package so I
and built it myself, but for some reason it doesn't fire in my
$ 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.