On 05/08/2017 11:37 AM, Martin Sebor wrote:
The -Wformat-overflow warning newly enhanced in GCC 8.0 to detect
reading past the end of the source sequence misinterprets the size
argument to stpncpy as a request to read that many bytes from the
source sequence, rather than the number of bytes to write.  Like
strncpy, the function never reads past the end of the source string.

This constraint is already handled correctly for strncpy by
the check_sizes function so the fix is to simply remove the wrong
length handling from expand_builtin_stpncpy and let check_sizes
do the right thing.

The attached patch passes bootstrap and regression test on x86_64.

Martin

gcc-80669.diff


PR middle-end/80669 - Bad -Wstringop-overflow warnings for stpncpy

gcc/ChangeLog:

        PR middle-end/80669
        * builtins.c (expand_builtin_stpncpy): Simplify.

gcc/testsuite/ChangeLog:

        PR middle-end/80669
        * gcc.dg/builtin-stpncpy.c: New test.
OK.
jeff

Reply via email to