This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [testsuite, committed] Compile strncpy-fix-1.c with -Wno-stringop-truncation
- From: Martin Sebor <msebor at gmail dot com>
- To: Tom de Vries <Tom_deVries at mentor dot com>, Jeff Law <law at redhat dot com>, Gcc Patch List <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 15 Nov 2017 08:43:10 -0700
- Subject: Re: [testsuite, committed] Compile strncpy-fix-1.c with -Wno-stringop-truncation
- Authentication-results: sourceware.org; auth=none
- References: <13944863-99a8-4144-1703-c6e1a2f36425@gmail.com> <0bbc91cd-fcdb-be61-e1d0-4b230f23b1a9@redhat.com> <4f4fbd4c-cb46-b80d-5749-ebb6bb050bc4@gmail.com> <a0069a6d-d4a8-67df-e2f3-902dc7704ab2@redhat.com> <d1fd572a-6bff-d95b-1b9e-23527e8ea14b@gmail.com> <096cf240-55e1-37e1-2810-0594a76492c0@mentor.com>
On 11/15/2017 08:12 AM, Tom de Vries wrote:
[ Re: [PATCH 3/4] enhance overflow and truncation detection in strncpy
and strncat (PR 81117) ]
On 08/06/2017 10:07 PM, Martin Sebor wrote:
Part 3 of the series contains the meat of the patch: the new
-Wstringop-truncation option, and enhancements to -Wstringop-
overflow, and -Wpointer-sizeof-memaccess to detect misuses of
strncpy and strncat.
Martin
gcc-81117-3.diff
PR c/81117 - Improve buffer overflow checking in strncpy
gcc/testsuite/ChangeLog:
PR c/81117
* c-c++-common/Wsizeof-pointer-memaccess3.c: New test.
* c-c++-common/Wstringop-overflow.c: Same.
* c-c++-common/Wstringop-truncation.c: Same.
* c-c++-common/Wsizeof-pointer-memaccess2.c: Adjust.
* c-c++-common/attr-nonstring-2.c: New test.
* g++.dg/torture/Wsizeof-pointer-memaccess1.C: Adjust.
* g++.dg/torture/Wsizeof-pointer-memaccess2.C: Same.
* gcc.dg/torture/pr63554.c: Same.
* gcc.dg/Walloca-1.c: Disable macro tracking.
Hi,
this also caused a regression in strncpy-fix-1.c. I noticed it for nvptx
(but I also saw it in other test results, f.i. for
x86_64-unknown-freebsd12.0 at
https://gcc.gnu.org/ml/gcc-testresults/2017-11/msg01276.html ).
On linux you don't see this unless you add -Wsystem-headers:
Yes, some Glibc versions (I think 2.24 and prior) define strncpy
as a macro. The macro has been removed from newer versions, which
makes the warning show up inconsistently. I test on Fedora 25 with
the older Glibc so I don't see all these warnings.
I'm tracking the problem bug 82944.
...
$ gcc src/gcc/testsuite/gcc.dg/strncpy-fix-1.c
-fno-diagnostics-show-caret -fdiagnostics-color=never -O2 -Wall
-Wsystem-headers -S -o strncpy-fix-1.s
In file included from /usr/include/string.h:630,
from src/gcc/testsuite/gcc.dg/strncpy-fix-1.c:6:
src/gcc/testsuite/gcc.dg/strncpy-fix-1.c: In function ‘f’:
src/gcc/testsuite/gcc.dg/strncpy-fix-1.c:10:3: warning:
‘__builtin_strncpy’ output truncated before terminating nul copying 2
bytes from a string of the same length [-Wstringop-truncation]
...
Fixed by adding -Wno-stringop-truncation.
Committed as obvious.
Thanks
Martin