Calling strncpy in libiberty's dyn_string_insert() with the last argument equal to the length of the second triggers the warning:
/src/gcc/master/libiberty/dyn-string.c:280:3: warning: ‘strncpy’ output truncated before terminating nul copying as many bytes from a string as its length [-Wstringop-truncation]
280 | strncpy (dest->s + pos, src, length); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /src/gcc/master/libiberty/dyn-string.c:272:16: note: length computed here 272 | int length = strlen (src); | ^~~~~~~~~~~~ The attached patch avoids the warning by calling memcpy instead. I'll go ahead and commit the patch as obvious if there are no concerns/objections. Martin
libiberty/ChangeLog: * dyn-string.c (dyn_string_insert_cstr): Use memcpy instead of strncpy to avoid warnings. diff --git a/libiberty/dyn-string.c b/libiberty/dyn-string.c index ea711182ca5..8d2456b86c8 100644 --- a/libiberty/dyn-string.c +++ b/libiberty/dyn-string.c @@ -277,7 +277,7 @@ dyn_string_insert_cstr (dyn_string_t dest, int pos, const char *src) for (i = dest->length; i >= pos; --i) dest->s[i + length] = dest->s[i]; /* Splice in the new stuff. */ - strncpy (dest->s + pos, src, length); + memcpy (dest->s + pos, src, length); /* Compute the new length. */ dest->length += length; return 1;