From patchwork Thu Nov 1 17:21:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 29996 Received: (qmail 18840 invoked by alias); 1 Nov 2018 17:21:16 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 18824 invoked by uid 89); 1 Nov 2018 17:21:15 -0000 Authentication-Results: sourceware.org; auth=none 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, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: relay1.mentorg.com Date: Thu, 1 Nov 2018 17:21:08 +0000 From: Joseph Myers To: Subject: Avoid printf ("%s", NULL) in posix/bug-regex22.c [committed] Message-ID: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Building posix/bug-regex22.c fails with GCC mainline because of -Wformat-overflow= warnings for NULL arguments to %s formats. This is *not* testing how glibc handles such format arguments; in the context of the messages in question it makes no sense to pass NULL to such a %s format (the code passes s, inside "if (s == NULL)"). So this patch changes the code not to pass such a format argument at all (which means the string passed is constant, so no need to use printf at all - however, there are two separate tests here with different length arguments passed to re_compile_pattern, so it *does* make sense to make the strings used different so that in the event of failure it's clear which one of the tests failed). Tested with build-many-glibcs.py with GCC mainline for aarch64-linux-gnu. Committed. 2018-11-01 Joseph Myers * posix/bug-regex22.c (main): Use puts with distinct error messages for unexpected success of re_compile_pattern, not printf with NULL argument to %s. diff --git a/posix/bug-regex22.c b/posix/bug-regex22.c index 2c561d8e43..73b222cbff 100644 --- a/posix/bug-regex22.c +++ b/posix/bug-regex22.c @@ -99,8 +99,8 @@ main (void) s = re_compile_pattern ("[[:DIGIT:]]", 11, &re); if (s == NULL) { - printf ("compilation of \"[[:DIGIT:]]\" pattern unexpectedly succeeded: %s\n", - s); + puts ("compilation of \"[[:DIGIT:]]\" pattern unexpectedly succeeded: " + "length 11"); result = 1; } @@ -109,8 +109,8 @@ main (void) s = re_compile_pattern ("[[:DIGIT:]]", 2, &re); if (s == NULL) { - printf ("compilation of \"[[:DIGIT:]]\" pattern unexpectedly succeeded: %s\n", - s); + puts ("compilation of \"[[:DIGIT:]]\" pattern unexpectedly succeeded: " + "length 2"); result = 1; }