[PATCH] avoid -Wstringop-truncation in Darwin bootstrap
Martin Sebor
msebor@gmail.com
Fri Nov 10 22:57:00 GMT 2017
On 11/10/2017 03:18 PM, Jeff Law wrote:
> 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.
Yes, that is correct.
> 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.
Committed in r254641.
Thanks
Martin
More information about the Gcc-patches
mailing list