[PATCH] use memcpy instead of strncpy for dyn_string insertion

Martin Sebor msebor@gmail.com
Thu Jan 28 17:27:29 GMT 2021


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-dyn-string.diff
Type: text/x-patch
Size: 631 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210128/da0d6219/attachment-0001.bin>


More information about the Gcc-patches mailing list