[1/8] tests: fix warn unused result

Message ID 20230418121130.844302-2-fberat@redhat.com
State Superseded
Headers
Series Fix warn unused result |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Frederic Berat April 18, 2023, 12:11 p.m. UTC
  When enabling _FORTIFY_SOURCE, some functions now lead to warnings when
their result is not checked.
---
 argp/argp-test.c               | 14 +++++++++++---
 assert/test-assert-perr.c      | 13 +++++++------
 assert/test-assert.c           | 13 +++++++------
 crypt/cert.c                   |  6 +++++-
 dirent/tst-fdopendir.c         | 13 +++++++++++--
 elf/tst-stackguard1.c          |  2 +-
 io/tst-copy_file_range.c       |  2 +-
 io/tst-faccessat.c             |  6 +++++-
 io/tst-fchmodat.c              |  6 +++++-
 io/tst-fchownat.c              |  6 +++++-
 io/tst-fstatat.c               |  6 +++++-
 io/tst-futimesat.c             |  6 +++++-
 io/tst-linkat.c                |  6 +++++-
 io/tst-openat.c                |  6 +++++-
 io/tst-renameat.c              |  6 +++++-
 io/tst-symlinkat.c             |  6 +++++-
 io/tst-unlinkat.c              |  6 +++++-
 libio/bug-fseek.c              | 15 ++++++++++++---
 libio/bug-mmap-fflush.c        | 12 ++++++++++--
 libio/bug-ungetc.c             |  7 ++++++-
 libio/bug-ungetc3.c            |  7 ++++++-
 libio/bug-ungetc4.c            |  7 ++++++-
 libio/bug-wfflush.c            |  6 +++++-
 libio/bug-wsetpos.c            |  7 ++++++-
 misc/tst-efgcvt-template.c     |  4 ++--
 misc/tst-error1.c              |  2 +-
 nptl/tst-cancel7.c             |  2 +-
 nptl/tst-cleanup4.c            |  6 +++++-
 nptl/tst-stackguard1.c         |  8 ++++++--
 nptl/tst-tls3mod.c             |  4 ++--
 nss/tst-nss-db-endpwent.c      |  6 +++++-
 nss/tst-reload2.c              |  6 +++++-
 posix/tst-chmod.c              |  9 +++++++--
 posix/tst-execl2.c             |  4 ++--
 posix/tst-execle2.c            |  4 ++--
 posix/tst-execlp2.c            |  7 +++----
 posix/tst-execv2.c             |  3 +--
 posix/tst-execve2.c            |  3 +--
 posix/tst-execvp2.c            |  6 ++----
 posix/tst-getopt-cancel.c      |  2 +-
 posix/tst-nice.c               |  3 +--
 posix/wordexp-test.c           | 12 ++++++++++--
 rt/tst-cpuclock2.c             |  2 +-
 rt/tst-cputimer1.c             |  2 +-
 rt/tst-cputimer2.c             |  2 +-
 rt/tst-cputimer3.c             |  2 +-
 stdio-common/bug12.c           | 15 ++++++++++-----
 stdio-common/bug19.c           |  9 +++++++--
 stdio-common/bug3.c            |  6 +++++-
 stdio-common/bug4.c            |  6 +++++-
 stdio-common/bug5.c            |  6 +++++-
 stdio-common/bug6.c            |  8 ++++----
 stdio-common/test-fwrite.c     |  8 ++++++--
 stdio-common/test_rdwr.c       |  3 ++-
 stdio-common/tst-cookie.c      |  4 +++-
 stdio-common/tst-fmemopen3.c   |  6 +++++-
 stdio-common/tst-fseek.c       |  3 +--
 stdio-common/tst-perror.c      |  6 +++++-
 stdio-common/tstscanf.c        | 14 ++++++++++++--
 stdlib/test-canon.c            | 25 +++++++++++++++++++++----
 support/test-container.c       | 18 +++++++++++-------
 sysdeps/pthread/tst-cancel11.c |  6 +++++-
 sysdeps/pthread/tst-cancel16.c |  6 +++++-
 sysdeps/pthread/tst-cancel20.c |  2 --
 sysdeps/pthread/tst-cancel21.c |  2 --
 sysdeps/pthread/tst-cancel4.c  |  6 ++++--
 sysdeps/pthread/tst-cancel6.c  |  3 ++-
 sysdeps/pthread/tst-cond18.c   |  2 +-
 sysdeps/pthread/tst-fini1mod.c |  6 +++++-
 sysdeps/pthread/tst-flock1.c   |  6 +++++-
 sysdeps/pthread/tst-flock2.c   |  6 +++++-
 sysdeps/pthread/tst-key1.c     | 10 +++++-----
 sysdeps/pthread/tst-signal1.c  |  6 +++++-
 sysdeps/pthread/tst-signal2.c  |  6 +++++-
 sysdeps/pthread/tst-timer.c    |  2 +-
 time/tst-cpuclock1.c           |  2 +-
 76 files changed, 356 insertions(+), 135 deletions(-)
  

Comments

Siddhesh Poyarekar April 18, 2023, 12:23 p.m. UTC | #1
On 2023-04-18 08:11, Frédéric Bérat via Libc-alpha wrote:
> When enabling _FORTIFY_SOURCE, some functions now lead to warnings when
> their result is not checked.

I haven't done a full review of this patch yet, but the first straight 
issue I can see is that you could use the x* functions in support/ in 
the tests to avoid repeating the error checking blocks in tests.  For 
example:

> ---
>   argp/argp-test.c               | 14 +++++++++++---
>   assert/test-assert-perr.c      | 13 +++++++------
>   assert/test-assert.c           | 13 +++++++------
>   crypt/cert.c                   |  6 +++++-
>   dirent/tst-fdopendir.c         | 13 +++++++++++--
>   elf/tst-stackguard1.c          |  2 +-
>   io/tst-copy_file_range.c       |  2 +-
>   io/tst-faccessat.c             |  6 +++++-
>   io/tst-fchmodat.c              |  6 +++++-
>   io/tst-fchownat.c              |  6 +++++-
>   io/tst-fstatat.c               |  6 +++++-
>   io/tst-futimesat.c             |  6 +++++-
>   io/tst-linkat.c                |  6 +++++-
>   io/tst-openat.c                |  6 +++++-
>   io/tst-renameat.c              |  6 +++++-
>   io/tst-symlinkat.c             |  6 +++++-
>   io/tst-unlinkat.c              |  6 +++++-
>   libio/bug-fseek.c              | 15 ++++++++++++---
>   libio/bug-mmap-fflush.c        | 12 ++++++++++--
>   libio/bug-ungetc.c             |  7 ++++++-
>   libio/bug-ungetc3.c            |  7 ++++++-
>   libio/bug-ungetc4.c            |  7 ++++++-
>   libio/bug-wfflush.c            |  6 +++++-
>   libio/bug-wsetpos.c            |  7 ++++++-
>   misc/tst-efgcvt-template.c     |  4 ++--
>   misc/tst-error1.c              |  2 +-
>   nptl/tst-cancel7.c             |  2 +-
>   nptl/tst-cleanup4.c            |  6 +++++-
>   nptl/tst-stackguard1.c         |  8 ++++++--
>   nptl/tst-tls3mod.c             |  4 ++--
>   nss/tst-nss-db-endpwent.c      |  6 +++++-
>   nss/tst-reload2.c              |  6 +++++-
>   posix/tst-chmod.c              |  9 +++++++--
>   posix/tst-execl2.c             |  4 ++--
>   posix/tst-execle2.c            |  4 ++--
>   posix/tst-execlp2.c            |  7 +++----
>   posix/tst-execv2.c             |  3 +--
>   posix/tst-execve2.c            |  3 +--
>   posix/tst-execvp2.c            |  6 ++----
>   posix/tst-getopt-cancel.c      |  2 +-
>   posix/tst-nice.c               |  3 +--
>   posix/wordexp-test.c           | 12 ++++++++++--
>   rt/tst-cpuclock2.c             |  2 +-
>   rt/tst-cputimer1.c             |  2 +-
>   rt/tst-cputimer2.c             |  2 +-
>   rt/tst-cputimer3.c             |  2 +-
>   stdio-common/bug12.c           | 15 ++++++++++-----
>   stdio-common/bug19.c           |  9 +++++++--
>   stdio-common/bug3.c            |  6 +++++-
>   stdio-common/bug4.c            |  6 +++++-
>   stdio-common/bug5.c            |  6 +++++-
>   stdio-common/bug6.c            |  8 ++++----
>   stdio-common/test-fwrite.c     |  8 ++++++--
>   stdio-common/test_rdwr.c       |  3 ++-
>   stdio-common/tst-cookie.c      |  4 +++-
>   stdio-common/tst-fmemopen3.c   |  6 +++++-
>   stdio-common/tst-fseek.c       |  3 +--
>   stdio-common/tst-perror.c      |  6 +++++-
>   stdio-common/tstscanf.c        | 14 ++++++++++++--
>   stdlib/test-canon.c            | 25 +++++++++++++++++++++----
>   support/test-container.c       | 18 +++++++++++-------
>   sysdeps/pthread/tst-cancel11.c |  6 +++++-
>   sysdeps/pthread/tst-cancel16.c |  6 +++++-
>   sysdeps/pthread/tst-cancel20.c |  2 --
>   sysdeps/pthread/tst-cancel21.c |  2 --
>   sysdeps/pthread/tst-cancel4.c  |  6 ++++--
>   sysdeps/pthread/tst-cancel6.c  |  3 ++-
>   sysdeps/pthread/tst-cond18.c   |  2 +-
>   sysdeps/pthread/tst-fini1mod.c |  6 +++++-
>   sysdeps/pthread/tst-flock1.c   |  6 +++++-
>   sysdeps/pthread/tst-flock2.c   |  6 +++++-
>   sysdeps/pthread/tst-key1.c     | 10 +++++-----
>   sysdeps/pthread/tst-signal1.c  |  6 +++++-
>   sysdeps/pthread/tst-signal2.c  |  6 +++++-
>   sysdeps/pthread/tst-timer.c    |  2 +-
>   time/tst-cpuclock1.c           |  2 +-
>   76 files changed, 356 insertions(+), 135 deletions(-)
> 
> diff --git a/argp/argp-test.c b/argp/argp-test.c
> index c7e20f6235..fa7f9694d1 100644
> --- a/argp/argp-test.c
> +++ b/argp/argp-test.c
> @@ -178,12 +178,20 @@ help_filter (int key, const char *text, void *input)
>     if (key == ARGP_KEY_HELP_POST_DOC && text)
>       {
>         time_t now = time (0);
> -      asprintf (&new_text, text, ctime (&now));
> +      if (asprintf (&new_text, text, ctime (&now)) < 0)

... this could be xasprintf,

> +	{
> +	  printf("Failed to execute asprintf: %m\n");
> +	  exit(1);
> +	}
>       }
>     else if (key == 'f')
>       /* Show the default for the --foonly option.  */
> -    asprintf (&new_text, "%s (ZOT defaults to %x)",
> -	      text, params->foonly_default);
> +    if (asprintf (&new_text, "%s (ZOT defaults to %x)",
> +	      text, params->foonly_default) < 0)
> +	{
> +	  printf("Failed to execute asprintf: %m\n");
> +	  exit(1);
> +	}
>     else
>       new_text = (char *)text;
>   
> diff --git a/assert/test-assert-perr.c b/assert/test-assert-perr.c
> index 8496db6ffd..ecfd4d14e5 100644
> --- a/assert/test-assert-perr.c
> +++ b/assert/test-assert-perr.c
> @@ -46,6 +46,7 @@ int
>   main(void)
>   {
>     volatile int failed = 1;  /* safety in presence of longjmp() */
> +  char *ret;
>   
>     fclose (stderr);
>     stderr = tmpfile ();
> @@ -70,16 +71,16 @@ main(void)
>       failed = 1; /* should not happen */
>   
>     rewind (stderr);
> -  fgets (buf, 160, stderr);
> -  if (!strstr(buf, strerror (1)))
> +  ret = fgets (buf, 160, stderr);
> +  if ((!ret && ferror(stderr)) || !strstr(buf, strerror (1)))

This could be a new xfgets, and so on.

I'd suggest making these test fixes into their own series, grouped by 
the x* functions, i.e. one patch for xasprintf, one for xfgets, etc.

Thanks,
Sid
  

Patch

diff --git a/argp/argp-test.c b/argp/argp-test.c
index c7e20f6235..fa7f9694d1 100644
--- a/argp/argp-test.c
+++ b/argp/argp-test.c
@@ -178,12 +178,20 @@  help_filter (int key, const char *text, void *input)
   if (key == ARGP_KEY_HELP_POST_DOC && text)
     {
       time_t now = time (0);
-      asprintf (&new_text, text, ctime (&now));
+      if (asprintf (&new_text, text, ctime (&now)) < 0)
+	{
+	  printf("Failed to execute asprintf: %m\n");
+	  exit(1);
+	}
     }
   else if (key == 'f')
     /* Show the default for the --foonly option.  */
-    asprintf (&new_text, "%s (ZOT defaults to %x)",
-	      text, params->foonly_default);
+    if (asprintf (&new_text, "%s (ZOT defaults to %x)",
+	      text, params->foonly_default) < 0)
+	{
+	  printf("Failed to execute asprintf: %m\n");
+	  exit(1);
+	}
   else
     new_text = (char *)text;
 
diff --git a/assert/test-assert-perr.c b/assert/test-assert-perr.c
index 8496db6ffd..ecfd4d14e5 100644
--- a/assert/test-assert-perr.c
+++ b/assert/test-assert-perr.c
@@ -46,6 +46,7 @@  int
 main(void)
 {
   volatile int failed = 1;  /* safety in presence of longjmp() */
+  char *ret;
 
   fclose (stderr);
   stderr = tmpfile ();
@@ -70,16 +71,16 @@  main(void)
     failed = 1; /* should not happen */
 
   rewind (stderr);
-  fgets (buf, 160, stderr);
-  if (!strstr(buf, strerror (1)))
+  ret = fgets (buf, 160, stderr);
+  if ((!ret && ferror(stderr)) || !strstr(buf, strerror (1)))
     failed = 1;
 
-  fgets (buf, 160, stderr);
-  if (strstr (buf, strerror (0)))
+  ret = fgets (buf, 160, stderr);
+  if ((!ret && ferror(stderr)) || strstr (buf, strerror (0)))
     failed = 1;
 
-  fgets (buf, 160, stderr);
-  if (strstr (buf, strerror (2)))
+  ret = fgets (buf, 160, stderr);
+  if ((!ret && ferror(stderr)) || strstr (buf, strerror (2)))
     failed = 1;
 
   return failed;
diff --git a/assert/test-assert.c b/assert/test-assert.c
index 26b58d4dd3..22d250317c 100644
--- a/assert/test-assert.c
+++ b/assert/test-assert.c
@@ -48,6 +48,7 @@  main (void)
 {
 
   volatile int failed = 1;
+  char *ret;
 
   fclose (stderr);
   stderr = tmpfile ();
@@ -72,16 +73,16 @@  main (void)
     failed = 1; /* should not happen */
 
   rewind (stderr);
-  fgets (buf, 160, stderr);
-  if (!strstr (buf, "1 == 2"))
+  ret = fgets (buf, 160, stderr);
+  if ((!ret && ferror(stderr)) || !strstr (buf, "1 == 2"))
     failed = 1;
 
-  fgets (buf, 160, stderr);
-  if (strstr (buf, "1 == 1"))
+  ret = fgets (buf, 160, stderr);
+  if ((!ret && ferror(stderr)) || strstr (buf, "1 == 1"))
     failed = 1;
 
-  fgets (buf, 160, stderr);
-  if (strstr (buf, "2 == 3"))
+  ret = fgets (buf, 160, stderr);
+  if ((!ret && ferror(stderr)) || strstr (buf, "2 == 3"))
     failed = 1;
 
   return failed;
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/dirent/tst-fdopendir.c b/dirent/tst-fdopendir.c
index 6321af1daa..ee645cf9af 100644
--- a/dirent/tst-fdopendir.c
+++ b/dirent/tst-fdopendir.c
@@ -22,7 +22,11 @@  do_test (void)
       return 1;
     }
 
-  write (fd, "hello", 5);
+  if (write (fd, "hello", 5) < 5)
+    {
+      printf ("Failed to write to file: %m\n");
+      return 1;
+    }
   close (fd);
 
   struct stat64 st;
@@ -43,7 +47,12 @@  do_test (void)
     }
 
   char buf[5];
-  read(fd, buf, sizeof (buf));
+  if (read(fd, buf, sizeof (buf)) < 0)
+    {
+      puts ("read failed");
+      return 1;
+    }
+
   close(fd);
 
   struct stat64 st2;
diff --git a/elf/tst-stackguard1.c b/elf/tst-stackguard1.c
index 2e65e36078..1a98a9da52 100644
--- a/elf/tst-stackguard1.c
+++ b/elf/tst-stackguard1.c
@@ -108,7 +108,7 @@  do_test (void)
 	  dup2 (fds[1], 2);
 	  close (fds[1]);
 
-	  system (command);
+	  if (system (command)) {}
 	  exit (0);
 	}
 
diff --git a/io/tst-copy_file_range.c b/io/tst-copy_file_range.c
index d1f3aaa5a9..bd64e9c42b 100644
--- a/io/tst-copy_file_range.c
+++ b/io/tst-copy_file_range.c
@@ -166,7 +166,7 @@  short_copy (void)
           inoff = 3;
           xlseek (infd, shift, SEEK_SET);
         }
-      ftruncate (outfd, 0);
+      xftruncate (outfd, 0);
       xlseek (outfd, 0, SEEK_SET);
       outoff = 0;
 
diff --git a/io/tst-faccessat.c b/io/tst-faccessat.c
index 7bdeed008c..5ef81b1451 100644
--- a/io/tst-faccessat.c
+++ b/io/tst-faccessat.c
@@ -96,7 +96,11 @@  do_test (void)
       puts ("file creation failed");
       return 1;
     }
-  write (fd, "hello", 5);
+  if (write (fd, "hello", 5) < 5)
+    {
+      printf ("Failed to write to file: %m\n");
+      return 1;
+    }
   puts ("file created");
 
   /* Before closing the file, try using this file descriptor to open
diff --git a/io/tst-fchmodat.c b/io/tst-fchmodat.c
index 7d4a8717ff..aeed98e0a8 100644
--- a/io/tst-fchmodat.c
+++ b/io/tst-fchmodat.c
@@ -98,7 +98,11 @@  do_test (void)
       puts ("file creation failed");
       return 1;
     }
-  write (fd, "hello", 5);
+  if (write (fd, "hello", 5) < 5)
+    {
+      puts ("failed to write to file");
+      return 1;
+    }
   puts ("file created");
 
   struct stat64 st1;
diff --git a/io/tst-fchownat.c b/io/tst-fchownat.c
index e8adf6229f..b206c04200 100644
--- a/io/tst-fchownat.c
+++ b/io/tst-fchownat.c
@@ -106,7 +106,11 @@  do_test (void)
       puts ("file creation failed");
       return 1;
     }
-  write (fd, "hello", 5);
+  if (write (fd, "hello", 5) < 5)
+    {
+      printf ("Failed to write to file: %m\n");
+      return 1;
+    }
   puts ("file created");
 
   struct stat64 st1;
diff --git a/io/tst-fstatat.c b/io/tst-fstatat.c
index 4766bb2e71..712cd5226d 100644
--- a/io/tst-fstatat.c
+++ b/io/tst-fstatat.c
@@ -94,7 +94,11 @@  do_test (void)
       puts ("file creation failed");
       return 1;
     }
-  write (fd, "hello", 5);
+  if (write (fd, "hello", 5) < 5)
+    {
+      puts ("failed to write to file");
+      return 1;
+    }
   puts ("file created");
 
   struct stat64 st1;
diff --git a/io/tst-futimesat.c b/io/tst-futimesat.c
index 3d41721f42..0e1d104623 100644
--- a/io/tst-futimesat.c
+++ b/io/tst-futimesat.c
@@ -114,7 +114,11 @@  do_test (void)
       puts ("file creation failed");
       return 1;
     }
-  write (fd, "hello", 5);
+  if (write (fd, "hello", 5) < 5)
+    {
+      puts ("failed to write to file");
+      return 1;
+    }
   puts ("file created");
 
   struct_stat st1;
diff --git a/io/tst-linkat.c b/io/tst-linkat.c
index 97445b7954..92b1cc65f7 100644
--- a/io/tst-linkat.c
+++ b/io/tst-linkat.c
@@ -94,7 +94,11 @@  do_test (void)
       puts ("file creation failed");
       return 1;
     }
-  write (fd, "hello", 5);
+  if (write (fd, "hello", 5) < 5)
+    {
+      puts ("failed to write to file");
+      return 1;
+    }
   puts ("file created");
 
   struct stat64 st1;
diff --git a/io/tst-openat.c b/io/tst-openat.c
index 741b8d0ad2..999fdb79ba 100644
--- a/io/tst-openat.c
+++ b/io/tst-openat.c
@@ -94,7 +94,11 @@  do_test (void)
       puts ("file creation failed");
       return 1;
     }
-  write (fd, "hello", 5);
+  if (write (fd, "hello", 5) < 5)
+    {
+      puts ("failed to write to file");
+      return 1;
+    }
 
   /* Before closing the file, try using this file descriptor to open
      another file.  This must fail.  */
diff --git a/io/tst-renameat.c b/io/tst-renameat.c
index 435302b52b..33885a4280 100644
--- a/io/tst-renameat.c
+++ b/io/tst-renameat.c
@@ -94,7 +94,11 @@  do_test (void)
       puts ("file creation failed");
       return 1;
     }
-  write (fd, "hello", 5);
+  if (write (fd, "hello", 5) < 5)
+    {
+      puts ("failed to write to file");
+      return 1;
+    }
   puts ("file created");
 
   struct stat64 st1;
diff --git a/io/tst-symlinkat.c b/io/tst-symlinkat.c
index 214a8e348e..e9aba970c7 100644
--- a/io/tst-symlinkat.c
+++ b/io/tst-symlinkat.c
@@ -94,7 +94,11 @@  do_test (void)
       puts ("file creation failed");
       return 1;
     }
-  write (fd, "hello", 5);
+  if (write (fd, "hello", 5) < 5)
+    {
+      puts ("failed to write to file");
+      return 1;
+    }
   puts ("file created");
 
   struct stat64 st1;
diff --git a/io/tst-unlinkat.c b/io/tst-unlinkat.c
index e21d56f9f7..027d91ba98 100644
--- a/io/tst-unlinkat.c
+++ b/io/tst-unlinkat.c
@@ -94,7 +94,11 @@  do_test (void)
       puts ("file creation failed");
       return 1;
     }
-  write (fd, "hello", 5);
+  if (write (fd, "hello", 5) < 5)
+    {
+      puts ("failed to write to file");
+      return 1;
+    }
   close (fd);
   puts ("file created");
 
diff --git a/libio/bug-fseek.c b/libio/bug-fseek.c
index 1b60580b53..509db8689e 100644
--- a/libio/bug-fseek.c
+++ b/libio/bug-fseek.c
@@ -48,7 +48,10 @@  do_test (void)
       perror ("fopen(\"r\")");
     }
 
-  fread (buf, 3, 1, f);
+  if (fread (buf, 3, 1, f) < 1)
+    {
+      perror ("fread");
+    }
   errno = 0;
   if (fseek (f, -10, SEEK_CUR) == 0)
     {
@@ -72,7 +75,10 @@  Got %d instead\n",
       perror ("fopen(\"r+\")");
     }
 
-  fread (buf, 3, 1, f);
+  if (fread (buf, 3, 1, f) < 1)
+    {
+      perror ("fread");
+    }
   errno = 0;
   if (fseek (f, -10, SEEK_CUR) == 0)
     {
@@ -96,7 +102,10 @@  Got %d instead\n",
       perror ("fopen(\"r+\")");
     }
 
-  fread (buf, 3, 1, f);
+  if (fread (buf, 3, 1, f) < 1)
+    {
+      perror ("fread");
+    }
   if (ftell (f) != 3)
     {
       puts ("ftell failed");
diff --git a/libio/bug-mmap-fflush.c b/libio/bug-mmap-fflush.c
index d8aa58985a..697d39816e 100644
--- a/libio/bug-mmap-fflush.c
+++ b/libio/bug-mmap-fflush.c
@@ -35,14 +35,22 @@  do_test (void)
   char buffer[1024];
 
   snprintf (buffer, sizeof (buffer), "echo 'From foo@bar.com' > %s", fname);
-  system (buffer);
+  if (system (buffer))
+    {
+      perror ("Failed to execute echo command %m\n");
+      exit (1);
+    }
   f = fopen (fname, "r");
   fseek (f, 0, SEEK_END);
   o = ftello (f);
   fseek (f, 0, SEEK_SET);
   fflush (f);
   snprintf (buffer, sizeof (buffer), "echo 'From bar@baz.edu' >> %s", fname);
-  system (buffer);
+  if (system (buffer))
+    {
+      perror ("Failed to execute echo command %m\n");
+      exit (1);
+    }
   fseek (f, o, SEEK_SET);
   if (fgets (buffer, 1024, f) == NULL)
     exit (1);
diff --git a/libio/bug-ungetc.c b/libio/bug-ungetc.c
index 51940b68f5..5db5417170 100644
--- a/libio/bug-ungetc.c
+++ b/libio/bug-ungetc.c
@@ -20,7 +20,12 @@  do_prepare (void)
       printf ("cannot create temporary file: %m\n");
       exit (1);
     }
-  write (fd, pattern, sizeof (pattern));
+
+  if (write (fd, pattern, sizeof (pattern)) < sizeof (pattern))
+    {
+      printf ("cannot write to temporary file: %m\n");
+      exit (1);
+    }
   close (fd);
 }
 
diff --git a/libio/bug-ungetc3.c b/libio/bug-ungetc3.c
index 0c83c1161e..2afe000d2a 100644
--- a/libio/bug-ungetc3.c
+++ b/libio/bug-ungetc3.c
@@ -20,7 +20,12 @@  do_prepare (void)
       printf ("cannot create temporary file: %m\n");
       exit (1);
     }
-  write (fd, pattern, sizeof (pattern));
+  if (write (fd, pattern, sizeof (pattern)) < sizeof (pattern))
+    {
+      printf ("cannot write to temporary file: %m\n");
+      exit (1);
+    }
+
   close (fd);
 }
 
diff --git a/libio/bug-ungetc4.c b/libio/bug-ungetc4.c
index 0bd02a570d..df47bcd263 100644
--- a/libio/bug-ungetc4.c
+++ b/libio/bug-ungetc4.c
@@ -36,7 +36,12 @@  do_prepare (void)
       printf ("cannot create temporary file: %m\n");
       exit (1);
     }
-  write (fd, pattern, sizeof (pattern) - 1);
+
+  if (write (fd, pattern, sizeof (pattern) - 1) < sizeof (pattern) - 1)
+    {
+      printf ("cannot write to temporary file: %m\n");
+      exit (1);
+    }
   close (fd);
 }
 
diff --git a/libio/bug-wfflush.c b/libio/bug-wfflush.c
index a8fd61e997..771c32e17b 100644
--- a/libio/bug-wfflush.c
+++ b/libio/bug-wfflush.c
@@ -20,7 +20,11 @@  do_prepare (void)
       printf ("cannot create temporary file: %m\n");
       exit (1);
     }
-  write (fd, "1!", 2);
+  if (write (fd, "1!", 2) < 2)
+    {
+      printf ("cannot write to temporary file: %m\n");
+      exit (1);
+    }
   close (fd);
 }
 
diff --git a/libio/bug-wsetpos.c b/libio/bug-wsetpos.c
index ccb22a4b62..39180ccee1 100644
--- a/libio/bug-wsetpos.c
+++ b/libio/bug-wsetpos.c
@@ -22,7 +22,12 @@  do_prepare (void)
       printf ("cannot create temporary file: %m\n");
       exit (1);
     }
-  write (fd, pattern, sizeof (pattern));
+  if (write (fd, pattern, sizeof (pattern)) < sizeof (pattern))
+    {
+      printf ("cannot write to temporary file: %m\n");
+      exit (1);
+    }
+
   close (fd);
 }
 
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/misc/tst-error1.c b/misc/tst-error1.c
index 9c4a62fbd0..65e3fd0c0e 100644
--- a/misc/tst-error1.c
+++ b/misc/tst-error1.c
@@ -9,7 +9,7 @@  static int
 do_test (int argc, char *argv[])
 {
   mtrace ();
-  (void) freopen (argc == 1 ? "/dev/stdout" : argv[1], "a", stderr);
+  if (freopen (argc == 1 ? "/dev/stdout" : argv[1], "a", stderr)) {}
   /* Orient the stream.  */
   fwprintf (stderr, L"hello world\n");
   char buf[20000];
diff --git a/nptl/tst-cancel7.c b/nptl/tst-cancel7.c
index 2835613a9b..e4196d9d11 100644
--- a/nptl/tst-cancel7.c
+++ b/nptl/tst-cancel7.c
@@ -43,7 +43,7 @@  tf (void *arg)
 {
   char *cmd = xasprintf ("%s --direct --sem %s --pidfile %s",
 			 command, semfilename, pidfilename);
-  system (cmd);
+  if (system (cmd)) {};
   /* This call should never return.  */
   return NULL;
 }
diff --git a/nptl/tst-cleanup4.c b/nptl/tst-cleanup4.c
index 1d3d53fb5f..64206c4ab6 100644
--- a/nptl/tst-cleanup4.c
+++ b/nptl/tst-cleanup4.c
@@ -64,7 +64,11 @@  fn_read (void)
     }
 
   char c;
-  read (fds[0], &c, 1);
+  if (read (fds[0], &c, 1) < 1)
+    {
+      printf ("%s: read failed\n", __FUNCTION__);
+      exit (1);
+    }
 }
 
 
diff --git a/nptl/tst-stackguard1.c b/nptl/tst-stackguard1.c
index b9cf6844de..96cfcb02f7 100644
--- a/nptl/tst-stackguard1.c
+++ b/nptl/tst-stackguard1.c
@@ -96,7 +96,11 @@  do_test (void)
 	else if (ret != NULL)
 	  return 1;
 
-      write (2, &stack_chk_guard_copy, sizeof (stack_chk_guard_copy));
+      if (write (2, &stack_chk_guard_copy, sizeof (stack_chk_guard_copy)) < 0)
+	{
+	  puts("failed to write stack_chk_guard_copy");
+	  return 1;
+	}
       return 0;
     }
 
@@ -138,7 +142,7 @@  do_test (void)
 	  dup2 (fds[1], 2);
 	  close (fds[1]);
 
-	  system (command);
+	  if (system (command)) {}
 	  exit (0);
 	}
 
diff --git a/nptl/tst-tls3mod.c b/nptl/tst-tls3mod.c
index c6e8910b1e..ba9e012204 100644
--- a/nptl/tst-tls3mod.c
+++ b/nptl/tst-tls3mod.c
@@ -43,7 +43,7 @@  handler (int sig)
 {
   if (sig != THE_SIG)
     {
-      write (STDOUT_FILENO, "wrong signal\n", 13);
+      if (write (STDOUT_FILENO, "wrong signal\n", 13) < 13) {}
       _exit (1);
     }
 
@@ -51,7 +51,7 @@  handler (int sig)
 
   if (sem_post (&s) != 0)
     {
-      write (STDOUT_FILENO, "sem_post failed\n", 16);
+      if (write (STDOUT_FILENO, "sem_post failed\n", 16) < 16) {}
       _exit (1);
     }
 }
diff --git a/nss/tst-nss-db-endpwent.c b/nss/tst-nss-db-endpwent.c
index 2b0fc1b064..519b73c41e 100644
--- a/nss/tst-nss-db-endpwent.c
+++ b/nss/tst-nss-db-endpwent.c
@@ -55,7 +55,11 @@  do_test (void)
 
   cmd = xasprintf ("%s/makedb -o /var/db/passwd.db /var/db/passwd.in",
 		   support_bindir_prefix);
-  system (cmd);
+  if (system (cmd) < 0)
+    {
+      printf("failed to prepare the test");
+      return 1;
+    }
   free (cmd);
 
   try_it ();
diff --git a/nss/tst-reload2.c b/nss/tst-reload2.c
index ba9b5b7687..b25e5e3528 100644
--- a/nss/tst-reload2.c
+++ b/nss/tst-reload2.c
@@ -121,7 +121,11 @@  do_test (void)
   /* Change the root dir.  */
 
   TEST_VERIFY (chroot ("/subdir") == 0);
-  chdir ("/");
+  if (chdir ("/") < 0)
+    {
+      printf("Failed to change directory: %m");
+      return 1;
+    }
 
   /* Check we're NOT using the "inner" nsswitch.conf.  */
 
diff --git a/posix/tst-chmod.c b/posix/tst-chmod.c
index b98a05a265..bec2d2b8eb 100644
--- a/posix/tst-chmod.c
+++ b/posix/tst-chmod.c
@@ -229,7 +229,12 @@  do_test (int argc, char *argv[])
   close (fd);
 
   snprintf (buf, buflen, "%s/..", testdir);
-  chdir (buf);
+  if (chdir (buf))
+    {
+      printf ("cannot change directory: %m\n");
+      result = 1;
+      goto fail;
+    }
   /* We are now in the directory above the one we create the test
      directory in.  */
 
@@ -349,7 +354,7 @@  do_test (int argc, char *argv[])
     }
 
  fail:
-  chdir (startdir);
+  if (chdir (startdir)) {}
 
   /* Remove all the files.  */
   chmod (testdir, 0700);
diff --git a/posix/tst-execl2.c b/posix/tst-execl2.c
index 5b74959ef8..3c22ecce5c 100644
--- a/posix/tst-execl2.c
+++ b/posix/tst-execl2.c
@@ -18,8 +18,8 @@  prepare (int argc, char *argv[])
 {
   char *buf;
   int off;
-  asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]);
-  if (buf == NULL)
+
+  if (asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]) < 0 || buf == NULL)
     {
       puts ("asprintf  failed");
       exit (1);
diff --git a/posix/tst-execle2.c b/posix/tst-execle2.c
index 0430b7b573..28d3071dd9 100644
--- a/posix/tst-execle2.c
+++ b/posix/tst-execle2.c
@@ -18,8 +18,8 @@  prepare (int argc, char *argv[])
 {
   char *buf;
   int off;
-  asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]);
-  if (buf == NULL)
+
+  if (asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]) < 0 || buf == NULL)
     {
       puts ("asprintf  failed");
       exit (1);
diff --git a/posix/tst-execlp2.c b/posix/tst-execlp2.c
index 81a723dda4..797a320bb5 100644
--- a/posix/tst-execlp2.c
+++ b/posix/tst-execlp2.c
@@ -22,8 +22,8 @@  prepare (int argc, char *argv[])
 {
   char *buf;
   int off;
-  asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]);
-  if (buf == NULL)
+
+  if (asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]) < 0 || buf == NULL)
     {
       puts ("asprintf  failed");
       exit (1);
@@ -59,8 +59,7 @@  do_test (void)
       return 1;
     }
   char *path;
-  asprintf (&path, "%s:../libio:../elf", bindir);
-  if (path == NULL)
+  if (asprintf (&path, "%s:../libio:../elf", bindir) < 0 || path == NULL)
     {
       puts ("asprintf  failed");
       return 1;
diff --git a/posix/tst-execv2.c b/posix/tst-execv2.c
index a5168a269c..2de3286a6d 100644
--- a/posix/tst-execv2.c
+++ b/posix/tst-execv2.c
@@ -18,8 +18,7 @@  prepare (int argc, char *argv[])
 {
   char *buf;
   int off;
-  asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]);
-  if (buf == NULL)
+  if (asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]) < 0 || buf == NULL)
     {
       puts ("asprintf  failed");
       exit (1);
diff --git a/posix/tst-execve2.c b/posix/tst-execve2.c
index 1a804e94fd..57da680536 100644
--- a/posix/tst-execve2.c
+++ b/posix/tst-execve2.c
@@ -18,8 +18,7 @@  prepare (int argc, char *argv[])
 {
   char *buf;
   int off;
-  asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]);
-  if (buf == NULL)
+  if (asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]) < 0 || buf == NULL)
     {
       puts ("asprintf  failed");
       exit (1);
diff --git a/posix/tst-execvp2.c b/posix/tst-execvp2.c
index 440dfab438..ab6c3ee175 100644
--- a/posix/tst-execvp2.c
+++ b/posix/tst-execvp2.c
@@ -25,8 +25,7 @@  prepare (int argc, char *argv[])
 {
   char *buf;
   int off;
-  asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]);
-  if (buf == NULL)
+  if (asprintf (&buf, "cp %s %n%s-copy", argv[0], &off, argv[0]) < 0 || buf == NULL)
     {
       puts ("asprintf  failed");
       exit (1);
@@ -62,8 +61,7 @@  do_test (void)
       return 1;
     }
   char *path;
-  asprintf (&path, "%s:../libio:../elf", bindir);
-  if (path == NULL)
+  if (asprintf (&path, "%s:../libio:../elf", bindir) < 0 || path == NULL)
     {
       puts ("asprintf  failed");
       return 1;
diff --git a/posix/tst-getopt-cancel.c b/posix/tst-getopt-cancel.c
index 7167d1a914..24771ee82e 100644
--- a/posix/tst-getopt-cancel.c
+++ b/posix/tst-getopt-cancel.c
@@ -48,7 +48,7 @@  check_stderr (bool expect_errmsg, FILE *stderr_trapped)
       fputs (lineptr, stdout);
     }
   rewind (stderr_trapped);
-  ftruncate (fileno (stderr_trapped), 0);
+  if (ftruncate (fileno (stderr_trapped), 0) < 0) {}
   return got_errmsg == expect_errmsg;
 }
 
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 bae27d6cee..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);
 
@@ -332,7 +336,11 @@  do_test (int argc, char *argv[])
   if (cwd == NULL)
     cwd = "..";
 
-  chdir (cwd);
+  if (chdir (cwd) < 0)
+    {
+      printf ("failed to change dir: %m");
+      return 1;
+    }
   rmdir (tmpdir);
 
   return 0;
diff --git a/rt/tst-cpuclock2.c b/rt/tst-cpuclock2.c
index e4584d8791..22f20870f8 100644
--- a/rt/tst-cpuclock2.c
+++ b/rt/tst-cpuclock2.c
@@ -55,7 +55,7 @@  chew_cpu (void *arg)
       for (int i = 0; i < 100; ++i)
 	for (size_t j = 0; j < sizeof buf; ++j)
 	  buf[j] = 0xbb;
-      write (nullfd, (char *) buf, sizeof buf);
+      if (write (nullfd, (char *) buf, sizeof buf)) {};
       close (nullfd);
     }
 
diff --git a/rt/tst-cputimer1.c b/rt/tst-cputimer1.c
index 8f5dd76cf2..ec75424a83 100644
--- a/rt/tst-cputimer1.c
+++ b/rt/tst-cputimer1.c
@@ -29,7 +29,7 @@  chew_cpu (void *arg)
       for (int i = 0; i < 100; ++i)
 	for (size_t j = 0; j < sizeof buf; ++j)
 	  buf[j] = 0xbb;
-      write (nullfd, (char *) buf, sizeof buf);
+      if (write (nullfd, (char *) buf, sizeof buf)) {}
       close (nullfd);
     }
 
diff --git a/rt/tst-cputimer2.c b/rt/tst-cputimer2.c
index 397d7998c0..7fb78fe485 100644
--- a/rt/tst-cputimer2.c
+++ b/rt/tst-cputimer2.c
@@ -32,7 +32,7 @@  chew_cpu (void *arg)
       for (int i = 0; i < 100; ++i)
 	for (size_t j = 0; j < sizeof buf; ++j)
 	  buf[j] = 0xbb;
-      write (nullfd, (char *) buf, sizeof buf);
+      if (write (nullfd, (char *) buf, sizeof buf)) {}
       close (nullfd);
     }
 
diff --git a/rt/tst-cputimer3.c b/rt/tst-cputimer3.c
index 056766a377..e8661b9cfc 100644
--- a/rt/tst-cputimer3.c
+++ b/rt/tst-cputimer3.c
@@ -33,7 +33,7 @@  chew_cpu (void)
       for (int i = 0; i < 100; ++i)
 	for (size_t j = 0; j < sizeof buf; ++j)
 	  buf[j] = 0xbb;
-      write (nullfd, (char *) buf, sizeof buf);
+      if (write (nullfd, (char *) buf, sizeof buf)) {}
       close (nullfd);
       if (getppid () == 1)
 	_exit (2);
diff --git a/stdio-common/bug12.c b/stdio-common/bug12.c
index 48610c0e78..820e91f618 100644
--- a/stdio-common/bug12.c
+++ b/stdio-common/bug12.c
@@ -20,24 +20,29 @@  main (void)
     }
   rewind (f);
 
-  fread (m, 4096 * 4 - 10, 1, f);
-  fread (b, 20, 1, f);
+  if (fread (m, 4096 * 4 - 10, 1, f) < 1)
+    failed = 1;
+  if (fread (b, 20, 1, f) < 1)
+    failed = 1;
   printf ("got %s (should be %s)\n", b, "zzzzzzzzzzxxxxxxxxxx");
   if (strcmp (b, "zzzzzzzzzzxxxxxxxxxx"))
     failed = 1;
 
   fseek (f, -40, SEEK_CUR);
-  fread (b, 20, 1, f);
+  if (fread (b, 20, 1, f) < 1)
+    failed = 1;
   printf ("got %s (should be %s)\n", b, "zzzzzzzzzzzzzzzzzzzz");
   if (strcmp (b, "zzzzzzzzzzzzzzzzzzzz"))
     failed = 1;
 
-  fread (b, 20, 1, f);
+  if (fread (b, 20, 1, f) < 1)
+    failed = 1;
   printf ("got %s (should be %s)\n", b, "zzzzzzzzzzxxxxxxxxxx");
   if (strcmp (b, "zzzzzzzzzzxxxxxxxxxx"))
     failed = 1;
 
-  fread (b, 20, 1, f);
+  if (fread (b, 20, 1, f) < 1)
+    failed = 1;
   printf ("got %s (should be %s)\n", b, "xxxxxxxxxxxxxxxxxxxx");
   if (strcmp (b, "xxxxxxxxxxxxxxxxxxxx"))
     failed = 1;
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/bug3.c b/stdio-common/bug3.c
index 62a6cab330..c764a5a442 100644
--- a/stdio-common/bug3.c
+++ b/stdio-common/bug3.c
@@ -32,7 +32,11 @@  main (void)
 	      char buf[25];
 
 	      buf[0] = j;
-	      fread (buf + 1, 1, 23, f);
+	      if (fread (buf + 1, 1, 23, f) < 23)
+		{
+		  printf ("%s\nTest FAILED!\n", buf);
+		  return 1;
+		}
 	      buf[24] = '\0';
 	      if (strcmp (buf, "Where does this text go?") != 0)
 		{
diff --git a/stdio-common/bug4.c b/stdio-common/bug4.c
index cf7fe116eb..d587dfcfd4 100644
--- a/stdio-common/bug4.c
+++ b/stdio-common/bug4.c
@@ -30,7 +30,11 @@  main (int argc, char *argv[])
   fseek (f, 8180L, 0);
   fwrite ("Where does this text come from?", 1, 31, f);
   fseek (f, 8180L, 0);
-  fread (buffer, 1, 31, f);
+  if (fread (buffer, 1, 31, f) < 31)
+    {
+      puts ("\nTest FAILED!");
+      return 1;
+    }
   fwrite (buffer, 1, 31, stdout);
   fclose (f);
   remove (filename);
diff --git a/stdio-common/bug5.c b/stdio-common/bug5.c
index 7bfe9b2b8d..e6ee6ceb41 100644
--- a/stdio-common/bug5.c
+++ b/stdio-common/bug5.c
@@ -60,7 +60,11 @@  main (void)
      the perhaps incompatible new shared libraries.  */
   unsetenv ("LD_LIBRARY_PATH");
 
-  asprintf (&printbuf, "cmp %s %s", inname, outname);
+  if (asprintf (&printbuf, "cmp %s %s", inname, outname) < 0)
+    {
+      perror ("asprintf");
+      return 1;
+    }
   result = system (printbuf);
   remove (inname);
   remove (outname);
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/test-fwrite.c b/stdio-common/test-fwrite.c
index 5677c6da80..3f39f3fd8b 100644
--- a/stdio-common/test-fwrite.c
+++ b/stdio-common/test-fwrite.c
@@ -57,11 +57,15 @@  do_test (void)
       return 1;
     }
 
-  asprintf (&line, "\
+  if (asprintf (&line, "\
 GDB is free software and you are welcome to distribute copies of it\n\
  under certain conditions; type \"show copying\" to see the conditions.\n\
 There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\
-");
+") < 0)
+    {
+      perror ("asprintf");
+      return 1;
+    }
 
   puts ("Test succeeded.");
   return 0;
diff --git a/stdio-common/test_rdwr.c b/stdio-common/test_rdwr.c
index 7825ca9358..9d7834c852 100644
--- a/stdio-common/test_rdwr.c
+++ b/stdio-common/test_rdwr.c
@@ -49,7 +49,8 @@  main (int argc, char **argv)
 
   (void) fputs (hello, f);
   rewind (f);
-  (void) fgets (buf, sizeof (buf), f);
+  if (!fgets (buf, sizeof (buf), f) && ferror (f))
+	  lose = 1;
   rewind (f);
   (void) fputs (buf, f);
   rewind (f);
diff --git a/stdio-common/tst-cookie.c b/stdio-common/tst-cookie.c
index 030e684562..76df5b4d13 100644
--- a/stdio-common/tst-cookie.c
+++ b/stdio-common/tst-cookie.c
@@ -77,7 +77,9 @@  do_test (void)
 
   f = fopencookie (THE_COOKIE, "r+", fcts);
 
-  fread (buf, 1, 1, f);
+  if (fread (buf, 1, 1, f) < 1)
+    ++errors;
+
   fwrite (buf, 1, 1, f);
   fseek (f, 0, SEEK_CUR);
   fclose (f);
diff --git a/stdio-common/tst-fmemopen3.c b/stdio-common/tst-fmemopen3.c
index 3cc2832edc..971d0bcf5e 100644
--- a/stdio-common/tst-fmemopen3.c
+++ b/stdio-common/tst-fmemopen3.c
@@ -153,7 +153,11 @@  do_test_read_seek_neg (const char *mode, const char *expected)
 
   FILE *fp = fmemopen (buf, sizeof (buf), mode);
   fseek (fp, offset, SEEK_END);
-  fread (tmp, tmps, 1, fp);
+  if (fread (tmp, tmps, 1, fp) < 1)
+    {
+      printf ("fread failed");
+      return 1;
+    }
 
   if (memcmp (tmp, expected, tmps) != 0)
     {
diff --git a/stdio-common/tst-fseek.c b/stdio-common/tst-fseek.c
index c4ac17cdf4..bacc390c27 100644
--- a/stdio-common/tst-fseek.c
+++ b/stdio-common/tst-fseek.c
@@ -44,8 +44,7 @@  do_test (void)
   if (tmpdir == NULL || tmpdir[0] == '\0')
     tmpdir = "/tmp";
 
-  asprintf (&fname, "%s/tst-fseek.XXXXXX", tmpdir);
-  if (fname == NULL)
+  if (asprintf (&fname, "%s/tst-fseek.XXXXXX", tmpdir) < 0 || fname == NULL)
     error (EXIT_FAILURE, errno, "cannot generate name for temporary file");
 
   /* Create a temporary file.   */
diff --git a/stdio-common/tst-perror.c b/stdio-common/tst-perror.c
index 57835e0c59..af0bbc261a 100644
--- a/stdio-common/tst-perror.c
+++ b/stdio-common/tst-perror.c
@@ -94,7 +94,11 @@  do_test (void)
     puts ("multibyte test succeeded");
 
   lseek (fd, 0, SEEK_SET);
-  ftruncate (fd, 0);
+  if (ftruncate (fd, 0) < 0)
+    {
+      printf ("cannot truncate file descriptor: %m\n");
+      exit (EXIT_FAILURE);
+    }
 
   if (dup2 (fd, 2) == -1)
     {
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 4edee73dd8..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)
@@ -154,7 +161,12 @@  do_test (int argc, char ** argv)
     }
 
   for (i = 0; i < (int) (sizeof (symlinks) / sizeof (symlinks[0])); ++i)
-    symlink (symlinks[i].value, symlinks[i].name);
+    if (symlink (symlinks[i].value, symlinks[i].name))
+      {
+        printf ("%s: Unable to create symlink for %s -> %s\n",
+		argv[0], symlinks[i].name, symlinks[i].value);
+        ++errors;
+      }
 
   int has_dir = mkdir ("doesExist", 0777) == 0;
 
@@ -205,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 e68f16eecf..f8d808f331 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");
@@ -1186,7 +1186,7 @@  main (int argc, char **argv)
       int status;
 
       /* Send the child's "outside" pid to it.  */
-      write (pipes[1], &child, sizeof(child));
+      xwrite (pipes[1], &child, sizeof(child));
       close (pipes[0]);
       close (pipes[1]);
 
@@ -1217,7 +1217,9 @@  main (int argc, char **argv)
 
   /* Get our "outside" pid from our parent.  We use this to help with
      debugging from outside the container.  */
-  read (pipes[0], &child, sizeof(child));
+  if (read (pipes[0], &child, sizeof(child)) < sizeof(child))
+    FAIL_EXIT1 ("Unable to read PID");
+
   close (pipes[0]);
   close (pipes[1]);
   sprintf (pid_buf, "%lu", (long unsigned)child);
@@ -1255,7 +1257,8 @@  main (int argc, char **argv)
 
       sprintf (tmp, "%lld %lld 1\n",
 	       (long long) (be_su ? 0 : original_uid), (long long) original_uid);
-      write (UMAP, tmp, strlen (tmp));
+      xwrite (UMAP, tmp, strlen (tmp));
+
       xclose (UMAP);
 
       /* We must disable setgroups () before we can map our groups, else we
@@ -1264,7 +1267,7 @@  main (int argc, char **argv)
       if (GMAP >= 0)
 	{
 	  /* We support kernels old enough to not have this.  */
-	  write (GMAP, "deny\n", 5);
+	  xwrite (GMAP, "deny\n", 5);
 	  xclose (GMAP);
 	}
 
@@ -1276,7 +1279,8 @@  main (int argc, char **argv)
 
       sprintf (tmp, "%lld %lld 1\n",
 	       (long long) (be_su ? 0 : original_gid), (long long) original_gid);
-      write (GMAP, tmp, strlen (tmp));
+      xwrite (GMAP, tmp, strlen (tmp));
+
       xclose (GMAP);
     }
 
diff --git a/sysdeps/pthread/tst-cancel11.c b/sysdeps/pthread/tst-cancel11.c
index 4dd84d6673..4e577f97ad 100644
--- a/sysdeps/pthread/tst-cancel11.c
+++ b/sysdeps/pthread/tst-cancel11.c
@@ -56,7 +56,11 @@  tf (void *arg)
 
   /* This call should block and be cancelable.  */
   char buf[20];
-  read (fd[0], buf, sizeof (buf));
+  if (read (fd[0], buf, sizeof (buf)) < sizeof (buf))
+    {
+      puts ("tf: read failed");
+      exit (1);
+    }
 
   pthread_cleanup_pop (0);
 
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-cancel20.c b/sysdeps/pthread/tst-cancel20.c
index 1d5c53049b..93f287aa4f 100644
--- a/sysdeps/pthread/tst-cancel20.c
+++ b/sysdeps/pthread/tst-cancel20.c
@@ -84,8 +84,6 @@  tf_body (void)
       exit (1);
     }
 
-  read (fd[0], &c, 1);
-
   pthread_cleanup_pop (0);
 }
 
diff --git a/sysdeps/pthread/tst-cancel21.c b/sysdeps/pthread/tst-cancel21.c
index bc4ff308f9..ec8bf0dba3 100644
--- a/sysdeps/pthread/tst-cancel21.c
+++ b/sysdeps/pthread/tst-cancel21.c
@@ -85,8 +85,6 @@  tf_body (void)
       exit (1);
     }
 
-  read (fd[0], &c, 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);
 
diff --git a/sysdeps/pthread/tst-cancel6.c b/sysdeps/pthread/tst-cancel6.c
index 63e6d49707..11a16cd564 100644
--- a/sysdeps/pthread/tst-cancel6.c
+++ b/sysdeps/pthread/tst-cancel6.c
@@ -25,7 +25,8 @@  static void *
 tf (void *arg)
 {
   char buf[100];
-  fgets (buf, sizeof (buf), arg);
+  if (!fgets (buf, sizeof (buf), arg))
+    puts ("fgets failed");
   /* This call should never return.  */
   return NULL;
 }
diff --git a/sysdeps/pthread/tst-cond18.c b/sysdeps/pthread/tst-cond18.c
index edac4fa4ff..ceeecbd70c 100644
--- a/sysdeps/pthread/tst-cond18.c
+++ b/sysdeps/pthread/tst-cond18.c
@@ -40,7 +40,7 @@  tf (void *id)
       while (!exiting)
 	{
 	  if ((spins++ % 1000) == 0)
-	    write (fd, ".", 1);
+	    if(write (fd, ".", 1)) {}
 	  pthread_mutex_unlock (&lock);
 
 	  pthread_mutex_lock (&lock);
diff --git a/sysdeps/pthread/tst-fini1mod.c b/sysdeps/pthread/tst-fini1mod.c
index cdadf034cd..cee1e3838b 100644
--- a/sysdeps/pthread/tst-fini1mod.c
+++ b/sysdeps/pthread/tst-fini1mod.c
@@ -32,7 +32,11 @@  tf (void *arg)
     }
 
   char buf[10];
-  read (fds[0], buf, sizeof (buf));
+  if (read (fds[0], buf, sizeof (buf)) < sizeof (buf))
+    {
+      puts ("can't read enough");
+      exit (1);
+    }
 
   puts ("read returned");
   exit (1);
diff --git a/sysdeps/pthread/tst-flock1.c b/sysdeps/pthread/tst-flock1.c
index 7eef9070ab..660f3f1e3e 100644
--- a/sysdeps/pthread/tst-flock1.c
+++ b/sysdeps/pthread/tst-flock1.c
@@ -56,7 +56,11 @@  do_test (void)
 
   unlink (tmp);
 
-  write (fd, "foobar xyzzy", 12);
+  if (write (fd, "foobar xyzzy", 12) < 12)
+    {
+      puts ("write failed");
+      exit (1);
+    }
 
   if (flock (fd, LOCK_EX | LOCK_NB) != 0)
     {
diff --git a/sysdeps/pthread/tst-flock2.c b/sysdeps/pthread/tst-flock2.c
index 8762e93b52..122ffe296f 100644
--- a/sysdeps/pthread/tst-flock2.c
+++ b/sysdeps/pthread/tst-flock2.c
@@ -70,7 +70,11 @@  do_test (void)
 
   int i;
   for (i = 0; i < 20; ++i)
-    write (fd, "foobar xyzzy", 12);
+    if (write (fd, "foobar xyzzy", 12) < 12)
+      {
+	puts ("write failed");
+	return 1;
+      }
 
   pthread_barrier_t *b;
   b = mmap (NULL, sizeof (pthread_barrier_t), PROT_READ | PROT_WRITE,
diff --git a/sysdeps/pthread/tst-key1.c b/sysdeps/pthread/tst-key1.c
index 933edafef8..f9560a9bf5 100644
--- a/sysdeps/pthread/tst-key1.c
+++ b/sysdeps/pthread/tst-key1.c
@@ -51,7 +51,7 @@  do_test (void)
 
 	if (pthread_setspecific (keys[i], (const void *) (i + 100l)) != 0)
 	  {
-	    write (2, "setspecific failed\n", 19);
+	    if (write (2, "setspecific failed\n", 19)) {};
 	    _exit (1);
 	  }
       }
@@ -60,13 +60,13 @@  do_test (void)
     {
       if (pthread_getspecific (keys[i]) != (void *) (i + 100l))
 	{
-	  write (2, "getspecific failed\n", 19);
+	  if (write (2, "getspecific failed\n", 19)) {};
 	  _exit (1);
 	}
 
       if (pthread_key_delete (keys[i]) != 0)
 	{
-	  write (2, "key_delete failed\n", 18);
+	  if (write (2, "key_delete failed\n", 18)) {};
 	  _exit (1);
 	}
     }
@@ -74,13 +74,13 @@  do_test (void)
   /* Now it must be once again possible to allocate keys.  */
   if (pthread_key_create (&keys[0], NULL) != 0)
     {
-      write (2, "2nd key_create failed\n", 22);
+      if (write (2, "2nd key_create failed\n", 22)) {};
       _exit (1);
     }
 
   if (pthread_key_delete (keys[0]) != 0)
     {
-      write (2, "2nd key_delete failed\n", 22);
+      if (write (2, "2nd key_delete failed\n", 22)) {};
       _exit (1);
     }
 
diff --git a/sysdeps/pthread/tst-signal1.c b/sysdeps/pthread/tst-signal1.c
index d1073e8459..7459e30031 100644
--- a/sysdeps/pthread/tst-signal1.c
+++ b/sysdeps/pthread/tst-signal1.c
@@ -105,7 +105,11 @@  do_test (void)
 
   int i;
   for (i = 0; i < 20; ++i)
-    write (fd, "foobar xyzzy", 12);
+    if (write (fd, "foobar xyzzy", 12) < 0)
+    {
+      puts ("write failed");
+      exit (1);
+    }
 
   b = mmap (NULL, sizeof (pthread_barrier_t), PROT_READ | PROT_WRITE,
 	    MAP_SHARED, fd, 0);
diff --git a/sysdeps/pthread/tst-signal2.c b/sysdeps/pthread/tst-signal2.c
index dfe7d9f64a..34c5fda7e5 100644
--- a/sysdeps/pthread/tst-signal2.c
+++ b/sysdeps/pthread/tst-signal2.c
@@ -111,7 +111,11 @@  do_test (void)
 
   int i;
   for (i = 0; i < 20; ++i)
-    write (fd, "foobar xyzzy", 12);
+    if (write (fd, "foobar xyzzy", 12) < 0)
+    {
+      puts ("write failed");
+      exit (1);
+    }
 
   b = mmap (NULL, sizeof (pthread_barrier_t), PROT_READ | PROT_WRITE,
 	    MAP_SHARED, fd, 0);
diff --git a/sysdeps/pthread/tst-timer.c b/sysdeps/pthread/tst-timer.c
index 47472ab8e1..0363a13ab2 100644
--- a/sysdeps/pthread/tst-timer.c
+++ b/sysdeps/pthread/tst-timer.c
@@ -44,7 +44,7 @@  signal_func (int sig)
 {
   static const char text[] = "signal_func\n";
   signal (sig, signal_func);
-  write (STDOUT_FILENO, text, sizeof text - 1);
+  if (write (STDOUT_FILENO, text, sizeof text - 1)) {};
 }
 
 static void
diff --git a/time/tst-cpuclock1.c b/time/tst-cpuclock1.c
index 6f2e70a58a..1fb22329e4 100644
--- a/time/tst-cpuclock1.c
+++ b/time/tst-cpuclock1.c
@@ -41,7 +41,7 @@  chew_cpu (void)
       for (int i = 0; i < 100; ++i)
 	for (size_t j = 0; j < sizeof buf; ++j)
 	  buf[j] = 0xbb;
-      write (nullfd, (char *) buf, sizeof buf);
+      if (write (nullfd, (char *) buf, sizeof buf)) {}
       close (nullfd);
       if (getppid () == 1)
 	_exit (2);