[PATCH 2/2] gcc8.1: fix strcat warning

Andy Green andy at warmcat.com
Sun Jun 17 04:28:13 CEST 2018



On 06/17/2018 05:52 AM, Christian Hesse wrote:
> John Keeping <john at keeping.me.uk> on Sat, 2018/06/16 14:11:
>> On Wed, Jun 13, 2018 at 07:34:07AM +0800, Andy Green wrote:
>>> ../ui-ssdiff.c: In function ‘replace_tabs’:
>>> ../ui-ssdiff.c:142:4: warning: ‘strncat’ output truncated copying between
>>> 1 and 8 bytes from a string of length 8 [-Wstringop-truncation]
>>> strncat(result, spaces, 8 - (strlen(result) % 8));
>>> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>>
>>> Actually the strncat that was there before intends that its
>>> stock of spaces gets truncated, and it's not a problem.
>>>
>>> However gcc8.1 is also right, normally truncation is undesirable.
>>>
>>> Make the code do the padding explicitly.
>>>
>>> Signed-off-by: Andy Green <andy at warmcat.com>
>>
>> Reviewed-by: John Keeping <john at keeping.me.uk>
> 
> Agreed, except the typo in commit message. This is about strncat, not strcat.
> 

OK... I fixed that and dropped the first patch.


More information about the CGit mailing list