The semantics of strncat() and strncpy() are non-obvious, so let's not use 'em.
Both zero all their remaining buffer space, and with strncat() the size is
the space left at the _end_ of the string (not the size of the buffer) so
it's way too easy to stomp memory you don't own. As long as we have to measure
stuff ourselves to get it right, just use memcpy().
if (len > 0) {
*list = xmalloc(sizeof(struct string_list) + len + 1);
(*list)->next = 0;
- strncpy((*list)->str, new, len);
+ memcpy((*list)->str, new, len);
(*list)->str[len] = 0;
list = &(*list)->next;
}
if (!len) sprintf(rnext->str, "%s/%s", cwd, filename);
else {
char *res = rnext->str;
- strncpy(res, path, len);
+
+ memcpy(res, path, len);
res += len;
*(res++) = '/';
strcpy(res, filename);