On 2/18/21 3:30 PM, Martin Sebor via Gcc-patches wrote:
> The "writing one too many bytes" form of -Wstringop-overflow is
> designed to trigger for strcpy(d, s) calls into allocated destinations
> whose size is the result of (or depends on) strlen(s).  But the warning
> is in code that's also called from handlers for bounded functions like
> memcpy and strncpy, and the code doesn't differentiate between the two
> kinds of callers, causing false positives.
>
> The attached patch corrects both the warning routine and its callers
> to properly distinguish these two classes of callers.  In addition,
> it corrects a mistake where -Wstringop-overflow is being issued for
> destinations of unknown size instead of the more appropriate
> -Wstringop-truncation.
>
> Tested on x86_64-linux.
>
> The bug is a P2 10/11 regression and I'm looking to commit this change
> both into the trunk and 10-branch.
>
> Martin
>
>
> gcc-97631.diff
>
> PR middle-end/97631 - bogus "writing one too many bytes" warning for memcpy 
> with strlen argument
>
> gcc/ChangeLog:
>
>       PR middle-end/97631
>       * tree-ssa-strlen.c (maybe_warn_overflow): Test rawmem.
>       (handle_builtin_stxncpy_strncat): Rename locals.  Determine
>       destination size from allocation calls.  Issue a more appropriate
>       kind of warning.
>       (handle_builtin_memcpy): Pass true as rawmem to maybe_warn_overflow.
>       (handle_builtin_memset): Same.
>
> gcc/testsuite/ChangeLog:
>
>       PR middle-end/97631
>       * c-c++-common/Wstringop-overflow.c: Remove unexpected warnings.
>       Add an xfail.
>       * c-c++-common/Wstringop-truncation.c: Add expected warnings.
>       * gcc.dg/Wstringop-overflow-10.c: Also enable -Wstringop-truncation.
>       * gcc.dg/Wstringop-overflow-65.c: New test.
OK
jeff

Reply via email to