On Tue, 2014-08-12 at 09:05 -0700, Steve Langasek wrote: [...] > Matthias, could you please have a look at the below test case? We have a > regression in the latest nfs-kernel-server build, which appears to be caused > by a gcc-4.9 bug. > > Should I work around this in nfs-utils, or is a quick fix possible in > gcc-4.9? > > > char buf[100]; > > > > void > > add_name(char *old) > > { > > char *cp = old; > > > > while (cp && *cp) { > > cp++; > > } > > __builtin_strncpy(buf, old, cp-old); [...] So far as I know (haven't checked the latest standard), pointer subtraction has undefined behaviour unless both operands point into (or one beyond) the same array. As this is not true of null pointers, the compiler may infer that old can't be null, so cp can't be null, so there is no need to check whether it is. I.e. this is a bug in nfs-utils, not the compiler. Ben. -- Ben Hutchings Humans are not rational beings; they are rationalising beings.
Attachment:
signature.asc
Description: This is a digitally signed message part