From: Jes Sorensen Date: Tue, 19 May 2020 00:19:53 +0000 (-0400) Subject: Include count for \0 character when using strncpy to implement strdup. X-Git-Tag: mdadm-4.2-rc1~53 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7d90f7603af6b59e7144cef6617a1e9dd42161bd;p=thirdparty%2Fmdadm.git Include count for \0 character when using strncpy to implement strdup. We have to include the \0 character in the length when copying a string with strncpy() for which length was found with strlen(). Otherwise the destination will not get null terminated - except that we explicitly zeroed it out earlier. This quiets down the compiler's warnings. Signed-off-by: Jes Sorensen --- diff --git a/dlink.c b/dlink.c index 3efa94b7..69aa7aa3 100644 --- a/dlink.c +++ b/dlink.c @@ -63,7 +63,7 @@ char *dl_strndup(char *s, int l) if (s == NULL) return NULL; n = dl_newv(char, l+1); - strncpy(n, s, l); + strncpy(n, s, l+1); n[l] = 0; return n; }