[PING] [PATCH] consider successor blocks when avoiding -Wstringop-truncation (PR 84468)

Martin Sebor msebor@gmail.com
Sun Feb 25 00:11:00 GMT 2018


Attached is an updated patch with a fix for a bad assumption
exposed by building the linux kernel.

On 02/19/2018 07:50 PM, Martin Sebor wrote:
> PR 84468 points out a false positive in -Wstringop-truncation
> in code like this:
>
>   struct A { char a[4]; };
>
>   void f (struct A *p, const struct A *q)
>   {
>     if (p->a)
>       strncpy (p->a, q->a, sizeof p->a - 1);   // warning here
>
>     p->a[3] = '\0';
>   }
>
> The warning is due to the code checking only the same basic block
> as the one with the strncpy call for an assignment to the destination
> to avoid it, but failing to check the successor basic block if there
> is no subsequent statement in the current block.  (Eliminating
> the conditional is being tracked in PR 21474.)
>
> The attached test case adds logic to avoid this false positive.
> I don't know under what circumstances there could be more than
> one successor block here so I don't handle that case.
>
> Tested on x86_64-linux.
>
> Martin

-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-84468.diff
Type: text/x-patch
Size: 5380 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20180225/a7c5d9c0/attachment.bin>


More information about the Gcc-patches mailing list