On Thu, Oct 09, 2014 at 01:54:57PM +0800, Rongqing Li wrote:
> The attachment is a piece of C code.
> When compile it with -O2 option, a segfault occurs:
> 
>       strncpy(new, old, cp-old);

It is a bug of course, but in the testcase.
Calling strncpy with NULL second argument, even when the size is 0,
is undefined behavior.
See http://gcc.gnu.org/gcc-4.9/porting_to.html

Reply via email to