]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
tests: fix warn unused results
authorFrédéric Bérat <fberat@redhat.com>
Thu, 1 Jun 2023 14:27:47 +0000 (16:27 +0200)
committerSiddhesh Poyarekar <siddhesh@sourceware.org>
Thu, 1 Jun 2023 17:01:32 +0000 (13:01 -0400)
With fortification enabled, few function calls return result need to be
checked, has they get the __wur macro enabled.
Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
crypt/cert.c
misc/tst-efgcvt-template.c
posix/tst-nice.c
posix/wordexp-test.c
stdio-common/bug19.c
stdio-common/bug6.c
stdio-common/tstscanf.c
stdlib/test-canon.c
support/test-container.c
sysdeps/pthread/tst-cancel16.c
sysdeps/pthread/tst-cancel4.c

index 32c4386caffd8da8971f05c78ea4aa162ee9327c..5b4277f76d42ae09806d9f56b42e301c5c429b65 100644 (file)
@@ -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++) {
index b924659a3d18c2b8c5378a0ca8f8a48e0187f4fe..87e3ebe4faaa18671dd74824486fdcae92c6009c 100644 (file)
@@ -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.  */
index fe9888b3f66c419ad96e13e6b9f30c0c1488364f..59cf953e274fd2169cf3a69136eb2a8f4469b3d8 100644 (file)
@@ -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;
index bae27d6cee0a8ef34af235ee2da4642d7f0f430d..524597d96b375657185179aa8019f37a849e1c1a 100644 (file)
@@ -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);
 
index e083304bda40efb4cb2f4c27d4d2d025164f5ad7..9a3deac3fc7c89b8a69813c7759cbea5011ac047 100644 (file)
@@ -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);
index 0db63a3b44e1bb0f03014d9fd07a25562461e99f..50098bf3f2d9a0b9014ab82a622914fb8db0fa5e 100644 (file)
@@ -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");
index 3a4ebf75240a3cc6e9bc5b03512faad282c58ffd..7e92df47205490fd2a5fffea0ae3bc61afbd0e87 100644 (file)
@@ -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
index 4edee73dd8d30f7b637a919f202c6cba81f2b877..bf19b1f1b1a5bca66dad7a78775cc9c2007fcc98 100644 (file)
@@ -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)
@@ -205,7 +210,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",
index d4ca41fe7c9eb086f88e6d65d17828aa1468da31..008ced2d2547fce51ba2c969de0681fe150ce747 100644 (file)
@@ -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");
index 511b9e1e917454853f7f4a31e70f2f7c62490341..d47c7c68cb860aa631396c17d9ae451e4cdef7b4 100644 (file)
@@ -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);
 
index 4f5c89314c1cb4ef612fb92c58af48e80e09ebd7..4c9e8670ca8d18430ca57647979c09338a4bce1b 100644 (file)
@@ -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);