Patchwork [libiberty] : Check result of fwrite in test-expandargv.c

login
register
mail settings
Submitter Uros Bizjak
Date Aug. 5, 2011, 9:51 p.m.
Message ID <CAFULd4bCKj0WCiLcfj+ghfxAC+nGgYjek_Qv8=KWRCm22VZwzg@mail.gmail.com>
Download mbox | patch
Permalink /patch/108743/
State New
Headers show

Comments

Uros Bizjak - Aug. 5, 2011, 9:51 p.m.
Hello!

My system warns during compilation of libiberty test-expandargv.c test:

gcc -DHAVE_CONFIG_H -g -O2 -I..
-I../../../gcc-svn/trunk/libiberty/testsuite/../../include
-DHAVE_CONFIG_H -I.. -o test-expandargv \
	../../../gcc-svn/trunk/libiberty/testsuite/test-expandargv.c ../libiberty.a
../../../gcc-svn/trunk/libiberty/testsuite/test-expandargv.c: In
function ‘writeout_test’:
../../../gcc-svn/trunk/libiberty/testsuite/test-expandargv.c:211:
warning: ignoring return value of ‘fwrite’, declared with attribute
warn_unused_result

Attached patch fixes this warning.

2011-08-05  Uros Bizjak  <ubizjak@gmail.com>

	* testsuite/test-expandargv.c (writeout_test): Check result of fwrite.

Tested on alphaev68-pc-linux-gnu and x86_64-pc-linux-gnu.

OK for mainline SVN and 4.6?

Uros.
Uros Bizjak - Aug. 6, 2011, 5:40 p.m.
On Fri, Aug 5, 2011 at 11:51 PM, Uros Bizjak <ubizjak@gmail.com> wrote:

> My system warns during compilation of libiberty test-expandargv.c test:
>
> gcc -DHAVE_CONFIG_H -g -O2 -I..
> -I../../../gcc-svn/trunk/libiberty/testsuite/../../include
> -DHAVE_CONFIG_H -I.. -o test-expandargv \
>        ../../../gcc-svn/trunk/libiberty/testsuite/test-expandargv.c ../libiberty.a
> ../../../gcc-svn/trunk/libiberty/testsuite/test-expandargv.c: In
> function ‘writeout_test’:
> ../../../gcc-svn/trunk/libiberty/testsuite/test-expandargv.c:211:
> warning: ignoring return value of ‘fwrite’, declared with attribute
> warn_unused_result
>
> Attached patch fixes this warning.
>
> 2011-08-05  Uros Bizjak  <ubizjak@gmail.com>
>
>        * testsuite/test-expandargv.c (writeout_test): Check result of fwrite.
>
> Tested on alphaev68-pc-linux-gnu and x86_64-pc-linux-gnu.

I have committed this patch as obvious.  Please also note, that size
and nitems arguments to fwrite were reversed.

Uros.

Patch

Index: testsuite/test-expandargv.c
===================================================================
--- testsuite/test-expandargv.c	(revision 177430)
+++ testsuite/test-expandargv.c	(working copy)
@@ -189,7 +189,7 @@  writeout_test (int test, const char * test_data)
 {
   char filename[256];
   FILE *fd;
-  size_t len;
+  size_t len, sys_fwrite;
   char * parse;
 
   /* Unique filename per test */
@@ -208,7 +208,10 @@  writeout_test (int test, const char * test_data)
   /* Run all possible replaces */
   run_replaces (parse);
 
-  fwrite (parse, len, sizeof (char), fd);
+  sys_fwrite = fwrite (parse, sizeof (char), len, fd);
+  if (sys_fwrite != len)
+    fatal_error (__LINE__, "Failed to write to test file.", errno);
+
   free (parse);
   fclose (fd);
 }