diff options
Diffstat (limited to 'string/strndup.c')
-rw-r--r-- | string/strndup.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/string/strndup.c b/string/strndup.c index 213a0c056b..c40d00fc59 100644 --- a/string/strndup.c +++ b/string/strndup.c @@ -24,13 +24,14 @@ Cambridge, MA 02139, USA. */ char * strndup (const char *s, size_t n) { - size_t len = strnlen (s) + 1; - char *new = malloc (len); + size_t len = strnlen (s); + char *new = malloc (len + 1); if (new == NULL) return NULL; memcpy (new, s, len); + new[len] = '\0'; return new; } |