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