From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32745 invoked by alias); 22 Oct 2018 13:09:26 -0000 Mailing-List: contact libc-stable-help@sourceware.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Subscribe: List-Archive: Sender: libc-stable-owner@sourceware.org Received: (qmail 32725 invoked by uid 89); 22 Oct 2018 13:09:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.100.1 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=abc X-Spam-Status: No, score=-25.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_PASS autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on sourceware.org X-Spam-Level: X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 22 Oct 2018 13:09:23 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 42CF8300194A for ; Mon, 22 Oct 2018 13:02:16 +0000 (UTC) Received: from oldenburg.str.redhat.com (dhcp-192-212.str.redhat.com [10.33.192.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id E329B6D78F for ; Mon, 22 Oct 2018 13:02:15 +0000 (UTC) Received: by oldenburg.str.redhat.com (Postfix, from userid 1000) id 56EBC4399457D; Mon, 22 Oct 2018 15:02:15 +0200 (CEST) Date: Mon, 01 Jan 2018 00:00:00 -0000 To: libc-stable@sourceware.org Subject: [2.26 COMMITTED] Fix string/tester.c build with GCC 8. User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-Id: <20181022130215.56EBC4399457D@oldenburg.str.redhat.com> From: fweimer@redhat.com (Florian Weimer) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 22 Oct 2018 13:02:16 +0000 (UTC) X-IsSubscribed: yes X-SW-Source: 2018-10/txt/msg00016.txt.bz2 From: Joseph Myers GCC 8 warns about more cases of string functions truncating their output or not copying a trailing NUL byte. This patch fixes testsuite build failures caused by such warnings in string/tester.c. In general, the warnings are disabled around the relevant calls using DIAG_* macros, since the relevant cases are being deliberately tested. In one case, the warning is with -Wstringop-overflow= instead of -Wstringop-truncation; in that case, the conditional is __GNUC_PREREQ (7, 0) (being the version where -Wstringop-overflow= was introduced), to allow the conditional to be removed sooner, since it's harmless to disable the warning for a GCC version where it doesn't actually occur. In the case of warnings for strncpy calls in test_memcmp, the calls in question are changed to use memcpy, as they don't copy a trailing NUL and the point of that code is to test memcmp rather than strncpy. Tested (compilation) with GCC 8 for x86_64-linux-gnu with build-many-glibcs.py (in conjunction with Martin's patch to allow glibc to build). * string/tester.c (test_stpncpy): Disable -Wstringop-truncation for stpncpy calls for GCC 8. (test_strncat): Disable -Wstringop-truncation warning for strncat calls for GCC 8. Disable -Wstringop-overflow= warning for one strncat call for GCC 7. (test_strncpy): Disable -Wstringop-truncation warning for strncpy calls for GCC 8. (test_memcmp): Use memcpy instead of strncpy for calls not copying trailing NUL. (cherry picked from commit 2e64ec9c9eac3aeb70f7cfa2392846c87c28068e) 2017-11-14 Joseph Myers * string/tester.c (test_stpncpy): Disable -Wstringop-truncation for stpncpy calls for GCC 8. (test_strncat): Disable -Wstringop-truncation warning for strncat calls for GCC 8. Disable -Wstringop-overflow= warning for one strncat call for GCC 7. (test_strncpy): Disable -Wstringop-truncation warning for strncpy calls for GCC 8. (test_memcmp): Use memcpy instead of strncpy for calls not copying trailing NUL. diff --git a/string/tester.c b/string/tester.c index 4b928b4f5e..66b11515b0 100644 --- a/string/tester.c +++ b/string/tester.c @@ -264,8 +264,15 @@ test_stpncpy (void) { it = "stpncpy"; memset (one, 'x', sizeof (one)); + DIAG_PUSH_NEEDS_COMMENT; +#if __GNUC_PREREQ (8, 0) + /* GCC 8 warns about stpncpy truncating output; this is deliberately + tested here. */ + DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-truncation"); +#endif check (stpncpy (one, "abc", 2) == one + 2, 1); check (stpncpy (one, "abc", 3) == one + 3, 2); + DIAG_POP_NEEDS_COMMENT; check (stpncpy (one, "abc", 4) == one + 3, 3); check (one[3] == '\0' && one[4] == 'x', 4); check (stpncpy (one, "abcd", 5) == one + 4, 5); @@ -420,13 +427,27 @@ test_strncat (void) equal (one, "cd", 9); (void) strcpy (one, "ab"); + DIAG_PUSH_NEEDS_COMMENT; +#if __GNUC_PREREQ (8, 0) + /* GCC 8 warns about strncat truncating output; this is deliberately + tested here. */ + DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-truncation"); +#endif (void) strncat (one, "cdef", 2); + DIAG_POP_NEEDS_COMMENT; equal (one, "abcd", 10); /* Count-limited. */ (void) strncat (one, "gh", 0); equal (one, "abcd", 11); /* Zero count. */ + DIAG_PUSH_NEEDS_COMMENT; +#if __GNUC_PREREQ (7, 0) + /* GCC 8 warns about strncat bound equal to source length; this is + deliberately tested here. */ + DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-overflow="); +#endif (void) strncat (one, "gh", 2); + DIAG_POP_NEEDS_COMMENT; equal (one, "abcdgh", 12); /* Count and length equal. */ DIAG_PUSH_NEEDS_COMMENT; @@ -523,11 +544,25 @@ test_strncpy (void) equal (one, "abc", 2); /* Did the copy go right? */ (void) strcpy (one, "abcdefgh"); + DIAG_PUSH_NEEDS_COMMENT; +#if __GNUC_PREREQ (8, 0) + /* GCC 8 warns about strncpy truncating output; this is deliberately + tested here. */ + DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-truncation"); +#endif (void) strncpy (one, "xyz", 2); + DIAG_POP_NEEDS_COMMENT; equal (one, "xycdefgh", 3); /* Copy cut by count. */ (void) strcpy (one, "abcdefgh"); + DIAG_PUSH_NEEDS_COMMENT; +#if __GNUC_PREREQ (8, 0) + /* GCC 8 warns about strncpy truncating output; this is deliberately + tested here. */ + DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-truncation"); +#endif (void) strncpy (one, "xyz", 3); /* Copy cut just before NUL. */ + DIAG_POP_NEEDS_COMMENT; equal (one, "xyzdefgh", 4); (void) strcpy (one, "abcdefgh"); @@ -542,7 +577,14 @@ test_strncpy (void) equal (one+5, "fgh", 9); (void) strcpy (one, "abc"); + DIAG_PUSH_NEEDS_COMMENT; +#if __GNUC_PREREQ (8, 0) + /* GCC 8 warns about strncpy truncating output; this is deliberately + tested here. */ + DIAG_IGNORE_NEEDS_COMMENT (8, "-Wstringop-truncation"); +#endif (void) strncpy (one, "xyz", 0); /* Zero-length copy. */ + DIAG_POP_NEEDS_COMMENT; equal (one, "abc", 10); (void) strncpy (one, "", 2); /* Zero-length source. */ @@ -1151,8 +1193,8 @@ test_memcmp (void) { char *a = one + i; char *b = two + i; - strncpy(a, "--------11112222", 16); - strncpy(b, "--------33334444", 16); + memcpy(a, "--------11112222", 16); + memcpy(b, "--------33334444", 16); check(memcmp(b, a, 16) > 0, cnt++); check(memcmp(a, b, 16) < 0, cnt++); }