Silence gcc-8 warnings

Franz Sirl Franz.Sirl-kernel@lauterbach.com
Tue Apr 24 12:35:00 GMT 2018


Am 2018-04-24 um 14:07 schrieb Michael Matz:> Hi,
 >
 > On Tue, 24 Apr 2018, Alan Modra wrote:
 >
 >> No, it is not a bug.  We have internal and external structs, and a
 >> field in the external struct that does not need to be NULL
 >> terminated.
 >
 > Ah, that's the crucial point (plus the zero termination for 
convenience of
 > the internal one).  Well, so the warning is correct still (according to
 > its intent, which may or may not be ill advised), but of course doesn't
 > take that into account.
 >
 >> What's more, we do want strncpy behaviour rather than memcpy, since for
 >> defensive programming we don't want to copy possibly uninitialized data
 >> past a string terminator in the internal representation, and do want to
 >> fill the external representation with zeros.
 >
 > Yeah, understood.

Hi,

unfortunately it's too late for GCC-8, but for GCC-9 I intend to open an 
enhancement request to split -Wstringop-truncation (and a similar case 
for -Wsizeof-pointer-memaccess).
Something like -Wstringop-truncation will not warn for strncpy's 
documented (!) natural usage to copy to a fixed size record (non-null 
terminated char array), but -Wstringop-truncation-strict 
(-Wstringop-truncation-secure?) will warn.

Franz Sirl





More information about the Binutils mailing list