[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#232025: memcpy, not strncpy

Most uses of strncpy(), like this one, are silly, because strncpy()
stops on a NUL but given the strnlen() call you know there aren't any
NULs.  Meanwhile, memcpy() is your friend.  I suggest:

+	len = strnlen(s, size);
+	str = malloc(len + 1);
+	memcpy(str, s, len);
+	str[len] = 0;

Chip Salzenberg               - a.k.a. -               <chip@pobox.com>
"I wanted to play hopscotch with the impenetrable mystery of existence,
    but he stepped in a wormhole and had to go in early."  // MST3K

Reply to: