From patchwork Thu Jun 1 14:27:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Berat X-Patchwork-Id: 1789098 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=YZWqtAZk; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QX7lz5xDnz20QB for ; Fri, 2 Jun 2023 00:28:31 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C7F1F3856965 for ; Thu, 1 Jun 2023 14:28:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C7F1F3856965 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685629709; bh=ftuZK6SaRmc4Zhf34xI220n09A7xUlD9sKmddoA4E5Y=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=YZWqtAZkUae+uWxFpgqXJcSc8JqWNRtvoafKH/frb6NSFoLZKHmp4bh5+62BGX2Zo Atq0lYAxzUQu/IApB1x0QGdmV8PDOa/TG1pte9uOdmmSJHKqb2PnBgKGinz8RAU5l5 BZQtDQRvKRzLr9XdhghhZdTj/sFxoqYIWa6u4VtY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 49CEB3857C4F for ; Thu, 1 Jun 2023 14:28:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 49CEB3857C4F Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-570-7eeuQ3-xM9WDJn9ziEIt4A-1; Thu, 01 Jun 2023 10:28:10 -0400 X-MC-Unique: 7eeuQ3-xM9WDJn9ziEIt4A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 416EB101A55C; Thu, 1 Jun 2023 14:28:10 +0000 (UTC) Received: from Nymeria-redhat.redhat.com (unknown [10.39.193.180]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7D10D8162; Thu, 1 Jun 2023 14:28:09 +0000 (UTC) To: libc-alpha@sourceware.org Cc: siddhesh@gotplt.org, fberat@redhat.com Subject: [PATCH v5 12/12] tests: fix warn unused results Date: Thu, 1 Jun 2023 16:27:47 +0200 Message-Id: <20230601142747.104444-6-fberat@redhat.com> In-Reply-To: <20230418121130.844302-2-fberat@redhat.com> References: <20230601142747.104444-1-fberat@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: =?utf-8?q?Fr=C3=A9d=C3=A9ric_B=C3=A9rat_via_Libc-alpha?= From: Frederic Berat Reply-To: =?utf-8?b?RnLDqWTDqXJpYyBCw6lyYXQ=?= Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" With fortification enabled, few function calls return result need to be checked, has they get the __wur macro enabled. Reviewed-by: Siddhesh Poyarekar --- Changes since v4: - Removed extra curly brackets crypt/cert.c | 6 +++++- misc/tst-efgcvt-template.c | 4 ++-- posix/tst-nice.c | 3 +-- posix/wordexp-test.c | 6 +++++- stdio-common/bug19.c | 9 +++++++-- stdio-common/bug6.c | 8 ++++---- stdio-common/tstscanf.c | 14 ++++++++++++-- stdlib/test-canon.c | 16 +++++++++++++--- support/test-container.c | 4 ++-- sysdeps/pthread/tst-cancel16.c | 6 +++++- sysdeps/pthread/tst-cancel4.c | 6 ++++-- 11 files changed, 60 insertions(+), 22 deletions(-) diff --git a/crypt/cert.c b/crypt/cert.c index 32c4386caf..5b4277f76d 100644 --- a/crypt/cert.c +++ b/crypt/cert.c @@ -99,7 +99,11 @@ get8 (char *cp) int i,j,t; for(i=0;i<8;i++){ - scanf("%2x",&t); + if (scanf("%2x",&t) < 1) + { + if(ferror(stdin)) + totfails++; + } if(feof(stdin)) good_bye(); for(j=0; j<8 ; j++) { diff --git a/misc/tst-efgcvt-template.c b/misc/tst-efgcvt-template.c index b924659a3d..87e3ebe4fa 100644 --- a/misc/tst-efgcvt-template.c +++ b/misc/tst-efgcvt-template.c @@ -200,8 +200,8 @@ special (void) output_error (NAME (ECVT), INFINITY, 10, "inf", 0, 0, p, decpt, sign); /* Simply make sure these calls with large NDIGITs don't crash. */ - (void) ECVT (123.456, 10000, &decpt, &sign); - (void) FCVT (123.456, 10000, &decpt, &sign); + p = ECVT (123.456, 10000, &decpt, &sign); + p = FCVT (123.456, 10000, &decpt, &sign); /* Some tests for the reentrant functions. */ /* Use a too small buffer. */ diff --git a/posix/tst-nice.c b/posix/tst-nice.c index fe9888b3f6..59cf953e27 100644 --- a/posix/tst-nice.c +++ b/posix/tst-nice.c @@ -58,8 +58,7 @@ do_test (void) /* BZ #18086. Make sure we don't reset errno. */ errno = EBADF; - nice (0); - if (errno != EBADF) + if (nice (0) == -1 || errno != EBADF) { printf ("FAIL: errno = %i, but wanted EBADF (%i)\n", errno, EBADF); return 1; diff --git a/posix/wordexp-test.c b/posix/wordexp-test.c index 87d537c931..057c89dd3c 100644 --- a/posix/wordexp-test.c +++ b/posix/wordexp-test.c @@ -253,7 +253,11 @@ do_test (int argc, char *argv[]) cwd = getcwd (NULL, 0); /* Set up arena for pathname expansion */ - tmpnam (tmpdir); + if (!tmpnam (tmpdir)) + { + printf ("Failed to create a temporary directory with a unique name: %m"); + return 1; + } xmkdir (tmpdir, S_IRWXU); TEST_VERIFY_EXIT (chdir (tmpdir) == 0); diff --git a/stdio-common/bug19.c b/stdio-common/bug19.c index e083304bda..9a3deac3fc 100644 --- a/stdio-common/bug19.c +++ b/stdio-common/bug19.c @@ -29,12 +29,17 @@ do_test (void) printf("checking sscanf\n"); int i, j, n; + int result = 0; i = j = n = 0; - FSCANF (fp, L(" %i - %i %n"), &i, &j, &n); + if (FSCANF (fp, L(" %i - %i %n"), &i, &j, &n) < 2) + { + printf ("FSCANF couldn't read all parameters %d\n", errno); + result = 1; + } + printf ("found %i-%i (length=%i)\n", i, j, n); - int result = 0; if (i != 7) { printf ("i is %d, expected 7\n", i); diff --git a/stdio-common/bug6.c b/stdio-common/bug6.c index 0db63a3b44..50098bf3f2 100644 --- a/stdio-common/bug6.c +++ b/stdio-common/bug6.c @@ -7,16 +7,16 @@ main (void) int i; int lost = 0; - scanf ("%2s", buf); + lost = (scanf ("%2s", buf) < 0); lost |= (buf[0] != 'X' || buf[1] != 'Y' || buf[2] != '\0'); if (lost) puts ("test of %2s failed."); - scanf (" "); - scanf ("%d", &i); + lost |= (scanf (" ") < 0); + lost |= (scanf ("%d", &i) < 0); lost |= (i != 1234); if (lost) puts ("test of %d failed."); - scanf ("%c", buf); + lost |= (scanf ("%c", buf) < 0); lost |= (buf[0] != 'L'); if (lost) puts ("test of %c failed.\n"); diff --git a/stdio-common/tstscanf.c b/stdio-common/tstscanf.c index 3a4ebf7524..7e92df4720 100644 --- a/stdio-common/tstscanf.c +++ b/stdio-common/tstscanf.c @@ -120,7 +120,12 @@ main (int argc, char **argv) int i; float x; char name[50]; - (void) fscanf (in, "%2d%f%*d %[0123456789]", &i, &x, name); + if (fscanf (in, "%2d%f%*d %[0123456789]", &i, &x, name) < 3) + { + fputs ("test failed!\n", stdout); + result = 1; + } + fprintf (out, "i = %d, x = %f, name = \"%.50s\"\n", i, x, name); if (i != 56 || x != 789.0F || strcmp (name, "56")) { @@ -164,7 +169,12 @@ main (int argc, char **argv) quant = 0.0; units[0] = item[0] = '\0'; count = fscanf (in, "%f%20s of %20s", &quant, units, item); - (void) fscanf (in, "%*[^\n]"); + if (fscanf (in, "%*[^\n]") < 0 && ferror (in)) + { + fputs ("test failed!\n", stdout); + result = 1; + } + fprintf (out, "count = %d, quant = %f, item = %.21s, units = %.21s\n", count, quant, item, units); if (count != ok[rounds-1].count || quant != ok[rounds-1].quant diff --git a/stdlib/test-canon.c b/stdlib/test-canon.c index 5a2e7e1e6e..407ad5c4a2 100644 --- a/stdlib/test-canon.c +++ b/stdlib/test-canon.c @@ -123,8 +123,13 @@ do_test (int argc, char ** argv) int i, errors = 0; char buf[PATH_MAX]; - getcwd (cwd, sizeof (buf)); - cwd_len = strlen (cwd); + if (getcwd (cwd, sizeof (buf))) + cwd_len = strlen (cwd); + else + { + printf ("%s: current working directory couldn't be retrieved\n", argv[0]); + ++errors; + } errno = 0; if (realpath (NULL, buf) != NULL || errno != EINVAL) @@ -210,7 +215,12 @@ do_test (int argc, char ** argv) free (result2); } - getcwd (buf, sizeof (buf)); + if (!getcwd (buf, sizeof (buf))) + { + printf ("%s: current working directory couldn't be retrieved\n", argv[0]); + ++errors; + } + if (strcmp (buf, cwd)) { printf ("%s: current working directory changed from %s to %s\n", diff --git a/support/test-container.c b/support/test-container.c index 37beb778d6..f51afefedb 100644 --- a/support/test-container.c +++ b/support/test-container.c @@ -714,8 +714,8 @@ check_for_unshare_hints (int require_pidns) continue; val = -1; /* Sentinel. */ - fscanf (f, "%d", &val); - if (val != files[i].bad_value) + int cnt = fscanf (f, "%d", &val); + if (cnt == 1 && val != files[i].bad_value) continue; printf ("To enable test-container, please run this as root:\n"); diff --git a/sysdeps/pthread/tst-cancel16.c b/sysdeps/pthread/tst-cancel16.c index 511b9e1e91..d47c7c68cb 100644 --- a/sysdeps/pthread/tst-cancel16.c +++ b/sysdeps/pthread/tst-cancel16.c @@ -50,7 +50,11 @@ tf (void *arg) pthread_cleanup_push (cl, NULL); /* This call should never return. */ - (void) lockf (fd, F_LOCK, 0); + if (lockf (fd, F_LOCK, 0)) + { + puts ("child thread: lockf failed"); + exit (1); + } pthread_cleanup_pop (0); diff --git a/sysdeps/pthread/tst-cancel4.c b/sysdeps/pthread/tst-cancel4.c index 4f5c89314c..4c9e8670ca 100644 --- a/sysdeps/pthread/tst-cancel4.c +++ b/sysdeps/pthread/tst-cancel4.c @@ -1009,7 +1009,8 @@ tf_pread (void *arg) pthread_cleanup_push (cl, NULL); char mem[10]; - pread (tempfd, mem, sizeof (mem), 0); + if (pread (tempfd, mem, sizeof (mem), 0) < 0) + FAIL_EXIT1 ("pread failed: %m"); pthread_cleanup_pop (0); @@ -1038,7 +1039,8 @@ tf_pwrite (void *arg) pthread_cleanup_push (cl, NULL); char mem[10]; - pwrite (tempfd, mem, sizeof (mem), 0); + if (pwrite (tempfd, mem, sizeof (mem), 0) <0) + FAIL_EXIT1 ("pwrite failed: %m"); pthread_cleanup_pop (0);