[PATCH] string: Add tests for zero length string inputs

Paul Eggert eggert@cs.ucla.edu
Tue Sep 23 13:58:00 GMT 2014


Richard Earnshaw wrote:

> if src+1 can point outside of the address space of the program

As Andreas points out, src+1 does not point outside the address space of 
the program.  It is a valid pointer.

> My reading of those sections also leads me to believe that memcpy could
> legitimately expect to perform "*(char*)dst = *(char*)dst", even if the
> length is zero.

I'm sorry, but this reading is incorrect.  If the size is zero, memcpy 
cannot store any bytes into the destination.  Any memcpy that does 
otherwise would break a lot of programs.

> I can think of no reason why 7.21.1/2 would explicitly
> require valid pointers when the length parameter was 0 unless it was
> intended that dereferencing could occur.

It caters to (unusual) architectures that require valid pointers in 
address registers even when the pointers are not dereferenced, e.g., 
loading a pointer into an address register will trap if the pointer is 
invalid.



More information about the Libc-alpha mailing list