Browse Source

Fix missing NULL terminator in xstrndup

The xstrndup function should take care of always adding a NULL
byte at the end of the copied string, to match the behavior of
the original strndup function.
master
Damien Goutte-Gattat 5 years ago
parent
commit
44abe07c87
  1. 3
      lib/xmem.c

3
lib/xmem.c

@ -96,10 +96,11 @@ xstrndup(const char *s, size_t n)
{
char *dup;
if ( ! (dup = malloc(n)) )
if ( ! (dup = malloc(n + 1)) )
mem_error(n);
strncpy(dup, s, n);
dup[n] = '\0';
return dup;
}

Loading…
Cancel
Save