Francis Giraldeau wrote: ... > Hi, > > Valgrind reports an invalid read, while I think the program is valid. > The program uses stpncpy() instead of strcpy(): > > #include <string.h> > #include <stdlib.h> > #include <stdio.h> > > int main(int argc, char **argv) { > char *dst =3D (char *) calloc(4, 1); > char *src =3D (char *) calloc(4, 1); > src[0] =3D 'a'; > src[1] =3D 'b'; > src[2] =3D 'c'; > src[3] =3D '\0'; > dst =3D stpncpy(dst, src, 3); > printf("%s %s\n", src, dst); > } > > The error is the following: ....
from the manpage: "RETURN VALUE stpncpy() returns a pointer to the terminating null byte in dest, or, if dest is not null-terminated, dest + n." songbird ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-users