This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [testsuite, committed] Compile strncpy-fix-1.c with -Wno-stringop-truncation


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]