From patchwork Wed Nov 15 15:12:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 838201 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-466868-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="BekTfcXr"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3ycSZP3YVDz9s7C for ; Thu, 16 Nov 2017 02:13:13 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=QjdZOazwP4khyiBHV wealiLCzyTJRv5cRTtUsLyqp690h3v/ri8EsAix8EeaF03m2aMW6RuI3cQ+dlgi2 XcBqd90B0yRaHcHBNevJCSU7S1+Mual7H/te9BW7Jef54KU3OmDJ8AcaR96wddQt csS9d/fTEEuxxFdPzxNmwR3gF8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=kKdzB7ZfV85i1XMca6SPX96 XWVg=; b=BekTfcXrR4DYaS0YKvT/ExA3QCQSutcC3dqV4H3oIRJ49ifFLtiD73+ SjXKmP8TMRyRpwOA3sDiT3mwiJKgmpof+7kzREA4GoCKvjDadgZib5Vt6JCIaBza T3M5X/aCk2R/yckffZfsUbfIszNYUwabRvH7RkzsL/6H99e8a9e0= Received: (qmail 64351 invoked by alias); 15 Nov 2017 15:13:05 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 64341 invoked by uid 89); 15 Nov 2017 15:13:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, KB_WAM_FROM_NAME_SINGLEWORD, RCVD_IN_DNSWL_NONE, SPF_PASS, URIBL_RED autolearn=ham version=3.3.2 spammy= X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 15 Nov 2017 15:13:02 +0000 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-MBX-04.mgc.mentorg.com) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1eEzN4-0004X3-QY from Tom_deVries@mentor.com ; Wed, 15 Nov 2017 07:12:58 -0800 Received: from [172.30.72.60] (137.202.0.87) by SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Wed, 15 Nov 2017 15:12:54 +0000 Subject: [testsuite, committed] Compile strncpy-fix-1.c with -Wno-stringop-truncation To: Martin Sebor , Jeff Law , Gcc Patch List References: <13944863-99a8-4144-1703-c6e1a2f36425@gmail.com> <0bbc91cd-fcdb-be61-e1d0-4b230f23b1a9@redhat.com> <4f4fbd4c-cb46-b80d-5749-ebb6bb050bc4@gmail.com> From: Tom de Vries Message-ID: <096cf240-55e1-37e1-2810-0594a76492c0@mentor.com> Date: Wed, 15 Nov 2017 16:12:49 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: X-ClientProxiedBy: svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) To SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) [ 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 Compile strncpy-fix-1.c with -Wno-stringop-truncation 2017-11-15 Tom de Vries * 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 void