public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Frédéric Bérat" <fberat@redhat.com>
To: libc-alpha@sourceware.org
Cc: siddhesh@gotplt.org, fberat@redhat.com
Subject: [PATCH v4 15/15] tests: fix warn unused results
Date: Fri, 28 Apr 2023 14:21:42 +0200	[thread overview]
Message-ID: <20230428122142.928135-16-fberat@redhat.com> (raw)
In-Reply-To: <20230418121130.844302-2-fberat@redhat.com>

With fortification enabled, few function calls return result need to be
checked, has they get the __wur macro enabled.
---
 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            | 18 +++++++++++++++---
 support/test-container.c       |  4 ++--
 sysdeps/pthread/tst-cancel16.c |  6 +++++-
 sysdeps/pthread/tst-cancel4.c  |  6 ++++--
 11 files changed, 62 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..61fe893609 100644
--- a/stdlib/test-canon.c
+++ b/stdlib/test-canon.c
@@ -123,8 +123,15 @@ 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 +217,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);
 
-- 
2.39.2


  parent reply	other threads:[~2023-04-28 12:35 UTC|newest]

Thread overview: 109+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-18 12:11 [PATCH 0/8] Fix warn unused result Frédéric Bérat
2023-04-18 12:11 ` [PATCH 1/8] tests: fix " Frédéric Bérat
2023-04-18 12:23   ` Siddhesh Poyarekar
2023-04-28 12:21   ` [PATCH v4 07/15] tests: fix warn unused result on asprintf calls Frédéric Bérat
2023-05-25  1:07     ` Siddhesh Poyarekar
2023-05-31 14:36       ` Frederic Berat
2023-04-28 12:21   ` [PATCH v4 08/15] tests: replace write by xwrite Frédéric Bérat
2023-05-25  1:16     ` Siddhesh Poyarekar
2023-06-01 16:39       ` Siddhesh Poyarekar
2023-04-28 12:21   ` [PATCH v4 09/15] tests: replace read by xread Frédéric Bérat
2023-04-28 12:21   ` [PATCH v4 10/15] tests: replace system by xsystem Frédéric Bérat
2023-05-25  1:22     ` Siddhesh Poyarekar
2023-04-28 12:21   ` [PATCH v4 11/15] tests: replace fread by xfread Frédéric Bérat
2023-04-28 12:21   ` [PATCH v4 12/15] tests: replace ftruncate by xftruncate Frédéric Bérat
2023-05-25  1:25     ` Siddhesh Poyarekar
2023-06-01 16:42       ` Siddhesh Poyarekar
2023-04-28 12:21   ` [PATCH v4 13/15] tests: replace fgets by xfgets Frédéric Bérat
2023-04-28 12:21   ` [PATCH v4 14/15] tests: Replace various function calls with their x variant Frédéric Bérat
2023-05-25  1:29     ` Siddhesh Poyarekar
2023-05-25 16:10       ` Frederic Berat
2023-04-28 12:21   ` Frédéric Bérat [this message]
2023-05-25  1:35     ` [PATCH v4 15/15] tests: fix warn unused results Siddhesh Poyarekar
2023-06-01 14:27   ` [PATCH v5 04/12] tests: fix warn unused result on asprintf calls Frédéric Bérat
2023-06-01 16:52     ` Siddhesh Poyarekar
2023-06-01 14:27   ` [PATCH v5 07/12] tests: replace system by xsystem Frédéric Bérat
2023-06-01 16:56     ` Siddhesh Poyarekar
2023-06-01 14:27   ` [PATCH v5 12/12] tests: fix warn unused results Frédéric Bérat
2023-06-01 16:57     ` Siddhesh Poyarekar
2023-04-18 12:11 ` [PATCH 2/8] catgets/gencat.c: fix warn unused result Frédéric Bérat
2023-04-18 12:36   ` Siddhesh Poyarekar
2023-04-28 12:21   ` [PATCH v4 01/15] " Frédéric Bérat
2023-05-24 22:47     ` Siddhesh Poyarekar
2023-06-01 14:27   ` [PATCH v5 01/12] " Frédéric Bérat
2023-06-01 16:47     ` Siddhesh Poyarekar
2023-04-18 12:11 ` [PATCH 3/8] inet/rcmd.c: " Frédéric Bérat
2023-04-18 12:37   ` Siddhesh Poyarekar
2023-04-18 13:40   ` Andreas Schwab
2023-04-18 13:50     ` Siddhesh Poyarekar
2023-04-18 12:11 ` [PATCH 4/8] locale/programs/locarchive.c: " Frédéric Bérat
2023-04-18 12:43   ` Siddhesh Poyarekar
2023-04-28 12:21   ` [PATCH v4 02/15] " Frédéric Bérat
2023-05-24 22:49     ` Siddhesh Poyarekar
2023-06-01 14:27   ` [PATCH v5 02/12] malloc/{memusage.c,memusagestat.c}: " Frédéric Bérat
2023-06-01 16:49     ` Siddhesh Poyarekar
2023-04-18 12:11 ` [PATCH 5/8] " Frédéric Bérat
2023-04-18 12:47   ` [PATCH 5/8] malloc/{memusage.c, memusagestat.c}: " Siddhesh Poyarekar
2023-04-28 12:21   ` [PATCH v4 03/15] malloc/{memusage.c,memusagestat.c}: " Frédéric Bérat
2023-05-25  0:50     ` Siddhesh Poyarekar
2023-06-01 15:55       ` [PATCH] Move {read,write}_all functions to a dedicated header Frédéric Bérat
2023-06-01 17:07         ` Siddhesh Poyarekar
2023-06-02  6:10           ` Frederic Berat
2023-06-02 10:01             ` Siddhesh Poyarekar
2023-04-18 12:11 ` [PATCH 6/8] nptl_db/thread_dbP.h: fix warn unused result Frédéric Bérat
2023-04-18 12:49   ` Siddhesh Poyarekar
2023-04-18 12:51     ` Siddhesh Poyarekar
2023-04-28 12:21   ` [PATCH v4 04/15] " Frédéric Bérat
2023-05-25  0:51     ` Siddhesh Poyarekar
2023-05-25  1:52       ` Siddhesh Poyarekar
2023-06-01 14:27   ` [PATCH v5 03/12] " Frédéric Bérat
2023-06-01 16:49     ` Siddhesh Poyarekar
2023-04-18 12:11 ` [PATCH 7/8] sunrpc/netname.c: " Frédéric Bérat
2023-04-18 12:51   ` Siddhesh Poyarekar
2023-04-28 12:21   ` [PATCH v4 05/15] " Frédéric Bérat
2023-05-25  0:53     ` Siddhesh Poyarekar
2023-04-18 12:11 ` [PATCH 8/8] sysdeps/pthread/eintr.c: " Frédéric Bérat
2023-04-18 12:54   ` Siddhesh Poyarekar
2023-04-28 12:21   ` [PATCH v4 06/15] " Frédéric Bérat
2023-05-25  0:59     ` Siddhesh Poyarekar
2023-04-28 12:21 ` [PATCH v4 00/15] Fix " Frédéric Bérat
2023-05-25  1:53   ` Siddhesh Poyarekar
2023-06-02 15:28 ` [PATCH v6 0/7] " Frédéric Bérat
2023-06-02 15:28   ` [PATCH v6 1/7] tests: fix warn unused result on asprintf calls Frédéric Bérat
2023-06-06  6:18     ` Siddhesh Poyarekar
2023-06-02 15:28   ` [PATCH v6 2/7] tests: replace read by xread Frédéric Bérat
2023-06-06  6:21     ` Siddhesh Poyarekar
2023-06-06  8:00       ` Frederic Berat
2023-06-12 14:22         ` Siddhesh Poyarekar
2023-06-07 19:04     ` Frederic Berat
2023-06-02 15:28   ` [PATCH v6 3/7] tests: replace system by xsystem Frédéric Bérat
2023-06-06 12:17     ` Siddhesh Poyarekar
2023-06-02 15:28   ` [PATCH v6 4/7] tests: replace fread by xfread Frédéric Bérat
2023-06-06 12:18     ` Siddhesh Poyarekar
2023-06-07 19:03     ` Frederic Berat
2023-06-02 15:28   ` [PATCH v6 5/7] tests: replace fgets by xfgets Frédéric Bérat
2023-06-06 12:20     ` Siddhesh Poyarekar
2023-06-08  5:50     ` Maxim Kuvyrkov
2023-06-08  6:57       ` Frederic Berat
2023-06-02 15:28   ` [PATCH v6 6/7] tests: Replace various function calls with their x variant Frédéric Bérat
2023-06-06 12:20     ` Siddhesh Poyarekar
2023-06-02 15:28   ` [PATCH v6 7/7] Move {read,write}_all functions to a dedicated header Frédéric Bérat
2023-06-06 12:21     ` Siddhesh Poyarekar
2023-06-12 15:18 ` [PATCH v7 0/4] Fix warn unused result Frédéric Bérat
2023-06-12 15:18   ` [PATCH v7 1/4] tests: replace read by xread Frédéric Bérat
2023-06-12 16:57     ` Joseph Myers
2023-06-13 14:22       ` Frederic Berat
2023-06-14  8:52     ` [PATCH v8 1/2] " Frédéric Bérat
2023-06-14 11:51       ` Siddhesh Poyarekar
2023-06-12 15:18   ` [PATCH v7 2/4] tests: replace system by xsystem Frédéric Bérat
2023-06-13 14:10     ` Siddhesh Poyarekar
2023-06-13 14:13     ` Adhemerval Zanella Netto
2023-06-13 14:16       ` Siddhesh Poyarekar
2023-06-14  8:52     ` [PATCH 2/2] " Frédéric Bérat
2023-06-14 11:53       ` Siddhesh Poyarekar
2023-06-12 15:18   ` [PATCH v7 3/4] tests: replace fread by xfread Frédéric Bérat
2023-06-13 23:57     ` Siddhesh Poyarekar
2023-06-12 15:18   ` [PATCH v7 4/4] tests: replace fgets by xfgets Frédéric Bérat
2023-06-13 12:23     ` Siddhesh Poyarekar
2023-06-13 18:25       ` Joseph Myers
2023-06-13 23:56         ` Siddhesh Poyarekar

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=20230428122142.928135-16-fberat@redhat.com \
    --to=fberat@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=siddhesh@gotplt.org \
    /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).