[PATCH] constrain writing one too many bytes" warning (PR 97631)

Martin Sebor msebor@gmail.com
Thu Feb 18 22:30:58 GMT 2021


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: gcc-97631.diff
Type: text/x-patch
Size: 15011 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210218/6a3d6e2b/attachment.bin>


More information about the Gcc-patches mailing list