This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] avoid -Wstringop-truncation in Darwin bootstrap


On 11/10/2017 12:55 PM, Martin Sebor wrote:
> A few not incorrect but not strictly intended (according to
> the function's original purpose) uses of strncpy trigger the
> new -Wstringop-truncation warning because they temporarily
> leave the copied string without a terminating nul.
> 
> The attached patch replaces these uses with memcpy to avoid
> the warning and make it clear (to both the reader and GCC)
> that the string being constructed is, in fact, not nul
> terminated until the last call to strcpy.
> 
> Tested by cross-compiling for x86_64-darwin.  For reference,
> with the attached patch applied the following is the list of
> outstanding warnings in the build.
> 
> Diagnostic                        Count   Unique    Files
> -Wsign-compare                        4        3        3
> -Wimplicit-fallthrough=               4        1        1
> 
> -Wimplicit-fallthrough Instances:
>   gengtype-lex.c:380
> 
> -Wsign-compare Instances:
>   arlex.c:1352
>   gengtype-lex.c:1367
>   syslex.c:1226
> 
> Martin
> 
> gcc-darwin-stringop-trunc.diff
> 
> 
> gcc/ChangeLog:
> 
> 	PR c/81117
> 	* config/darwin-c.c (framework_construct_pathname): Replace strncpy
> 	with memcpy.
> 	(find_subframework_file): Same.
So just to be 100% crystal clear.  This patch is not meant to change the
semantics of the code, it merely avoids code sequences that trigger the
new warning.  The code as-is is valid.

It's fairly common to have this kind of fallout and this looks well
within what we typically fix.  One could easily argue for these patches
independent of the warning since they make it clearer that the strings
in question are temporarily not terminated.

OK.

jeff


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]