This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] strncpy -Wstringop-truncation in bfd/
- From: Alan Modra <amodra at gmail dot com>
- To: John Reiser <jreiser at bitwagon dot com>
- Cc: binutils at sourceware dot org
- Date: Thu, 22 Feb 2018 21:13:07 +1030
- Subject: Re: [PATCH] strncpy -Wstringop-truncation in bfd/
- Authentication-results: sourceware.org; auth=none
- References: <e9a1a7e5-852a-10b5-c6b3-9560626d7205@bitwagon.com>
On Wed, Feb 21, 2018 at 12:44:06PM -0800, John Reiser wrote:
> Several uses of strncpy in bfd/* do not compile when using -Werror in gcc 8.0.x
> because of -Wstringop-truncation. A typical warning is:
>
> ../../binutils-gdb/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]
>
> A work-around is to use 'memcpy' instead of 'strncpy'. This spends
> a few more cycles each time; but it compiles, and runs correctly
> as long as the character arrays really are strings. Patch is attached.
But memcpy doesn't write zeros past the string terminator. If we're
writing to a file we want zeros rather than rubbish.
--
Alan Modra
Australia Development Lab, IBM