I am getting an invalid read error when the src string ends with \\n
, the error disappear when i remove \\n
:
#include
The error message seems to indicate that it's strlen
that read past the malloc
ed buffer allocated by strdup
. On a 32-bit platform, an optimal strlen
implementation could read 4 bytes at a time into a 32-bit register and do some bit-twiddling to see if there's a null byte in there. If near the end of the string, there are less than 4 bytes left, but 4 bytes are still read to perform the null byte check, then I could see this error getting printed. In that case, presumably the strlen
implementer would know if it's "safe" to do this on the particular platform, in which case the valgrind error is a false positive.