Fixes the following warning from gcc 9: In file included from /usr/include/string.h:494, from dmparser.c:8: In function ‘strncpy’, inlined from ‘merge_words’ at dmparser.c:41:2: /usr/include/bits/string_fortified.h:106:10: warning: ‘__builtin_strncpy’ specified bound depends on the length of the source argument [-Wstringop-overflow=] 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ dmparser.c: In function ‘merge_words’: dmparser.c:41:19: note: length computed here 41 | strncpy(p, word, strlen(word) + 1); | ^~~~~~~~~~~~ Signed-off-by: Martin Wilck <mwilck@xxxxxxxx> --- libmultipath/dmparser.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/libmultipath/dmparser.c b/libmultipath/dmparser.c index 04f675c1..a8b0b71a 100644 --- a/libmultipath/dmparser.c +++ b/libmultipath/dmparser.c @@ -21,24 +21,21 @@ static int merge_words(char **dst, char *word) { char * p = *dst; - int len; + int len, dstlen; - len = strlen(*dst) + strlen(word) + 1; - *dst = REALLOC(*dst, len + 1); + dstlen = strlen(*dst); + len = dstlen + strlen(word) + 2; + *dst = REALLOC(*dst, len); if (!*dst) { free(p); return 1; } - p = *dst; - - while (*p != '\0') - p++; - + p = *dst + dstlen; *p = ' '; ++p; - strncpy(p, word, strlen(word) + 1); + strncpy(p, word, len - dstlen - 1); return 0; } -- 2.21.0 -- dm-devel mailing list dm-devel@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/dm-devel