public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tom de Vries <Tom_deVries@mentor.com>
To: Martin Sebor <msebor@gmail.com>, Jeff Law <law@redhat.com>,
	Gcc Patch List	<gcc-patches@gcc.gnu.org>
Subject: [testsuite, committed] Compile strncpy-fix-1.c with -Wno-stringop-truncation
Date: Wed, 15 Nov 2017 15:30:00 -0000	[thread overview]
Message-ID: <096cf240-55e1-37e1-2810-0594a76492c0@mentor.com> (raw)
In-Reply-To: <d1fd572a-6bff-d95b-1b9e-23527e8ea14b@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1880 bytes --]

[ 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:
...
$ 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,
- Tom

[-- Attachment #2: 0001-Compile-strncpy-fix-1.c-with-Wno-stringop-truncation.patch --]
[-- Type: text/x-patch, Size: 738 bytes --]

Compile strncpy-fix-1.c with -Wno-stringop-truncation

2017-11-15  Tom de Vries  <tom@codesourcery.com>

	* gcc.dg/strncpy-fix-1.c: Add -Wno-stringop-truncation to dg-options.

---
 gcc/testsuite/gcc.dg/strncpy-fix-1.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gcc/testsuite/gcc.dg/strncpy-fix-1.c b/gcc/testsuite/gcc.dg/strncpy-fix-1.c
index b8bc916..b4fd4aa 100644
--- a/gcc/testsuite/gcc.dg/strncpy-fix-1.c
+++ b/gcc/testsuite/gcc.dg/strncpy-fix-1.c
@@ -1,7 +1,7 @@
 /* Test that use of strncpy does not result in a "value computed is
    not used" warning.  */
 /* { dg-do compile } */
-/* { dg-options "-O2 -Wall" } */
+/* { dg-options "-O2 -Wall -Wno-stringop-truncation" } */
 
 #include <string.h>
 void

  parent reply	other threads:[~2017-11-15 15:13 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-08 20:45 [PATCH] enhance overflow and truncation detection in strncpy and strncat (PR 81117) Martin Sebor
2017-07-18  2:51 ` [PING] " Martin Sebor
2017-07-25  3:10   ` [PING #2] " Martin Sebor
2017-07-31 17:29 ` Jeff Law
2017-07-31 19:42   ` Martin Sebor
2017-08-02 16:59     ` Jeff Law
2017-08-06 20:07       ` [PATCH 1/4] " Martin Sebor
2017-08-10  5:02         ` Jeff Law
2017-08-14 19:21           ` Martin Sebor
2017-08-06 20:07       ` [PATCH] " Martin Sebor
2017-08-09 19:21         ` Jeff Law
2017-08-06 20:07       ` [PATCH 3/4] " Martin Sebor
2017-08-10  7:17         ` Jeff Law
2017-08-10  7:39           ` Richard Biener
2017-08-10 20:21           ` Martin Sebor
2017-08-15  3:06             ` Martin Sebor
2017-08-23 21:11               ` [PING] " Martin Sebor
2017-08-29  5:07                 ` [PING 2] " Martin Sebor
2017-09-19 15:44                   ` [PING 3] " Martin Sebor
2017-09-26  2:27                     ` [PING 4] " Martin Sebor
2017-10-02 22:15             ` Jeff Law
2017-10-21  0:26               ` Martin Sebor
2017-11-04  3:49                 ` Jeff Law
2017-11-10  0:17                   ` Martin Sebor
2017-11-10  0:31                     ` Jeff Law
2017-11-14  9:24         ` [testsuite, committed] Require alloca for c-c++-common/Wstringop-truncation.c Tom de Vries
2017-11-15 15:30         ` Tom de Vries [this message]
2017-11-15 15:58           ` [testsuite, committed] Compile strncpy-fix-1.c with -Wno-stringop-truncation Martin Sebor
2017-08-06 20:07       ` [PATCH 2/4] enhance overflow and truncation detection in strncpy and strncat (PR 81117) Martin Sebor
2017-08-10  6:39         ` Jeff Law
2017-08-14 18:04           ` Martin Sebor
2017-08-14 18:29             ` Joseph Myers
2017-08-14 19:26               ` Martin Sebor
2017-08-14 20:41                 ` Joseph Myers
2017-08-14 20:44                   ` Martin Sebor
2017-08-15  3:03                     ` Joseph Myers
2017-11-10 23:03         ` Marc Glisse
2017-11-11 21:10           ` Martin Sebor
2017-08-06 20:07       ` [PATCH 4/4] " Martin Sebor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=096cf240-55e1-37e1-2810-0594a76492c0@mentor.com \
    --to=tom_devries@mentor.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    --cc=msebor@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).