Skip to contentSkip to conversation

gen_init_cpio: fixed fwrite warning

PATCH Applied Mike Frysinger 2 participants 2 messages Dec 9, 2009 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gen_init_cpio: fixed fwrite warning

On compilers with security warnings enabled by default, we get:

usr/gen_init_cpio.c: In function ‘cpio_mkfile’:
usr/gen_init_cpio.c:357: warning: ignoring return value of ‘fwrite’,
declared with attribute warn_unused_result

So check the return value and handle errors accordingly.

---
 usr/gen_init_cpio.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
usr/gen_init_cpio.c +4 -1
index 83b3dde..b2b3c2d 100644
@@ -354,7 +354,10 @@ static int cpio_mkfile(const char *name, const char *location,
 		push_pad();
 
 		if (size) {
-			fwrite(filebuf, size, 1, stdout);
+			if (fwrite(filebuf, size, 1, stdout) != 1) {
+				fprintf(stderr, "writing filebuf failed\n");
+				goto error;
+			}
 			offset += size;
 			push_pad();
 		}
Signature · 1 line
1.6.5.5
Applied
#1 lore raw
Quoted 9 lines · Mike Frysinger

On compilers with security warnings enabled by default, we get:

usr/gen_init_cpio.c: In function ‘cpio_mkfile’:
usr/gen_init_cpio.c:357: warning: ignoring return value of ‘fwrite’,
declared with attribute warn_unused_result

So check the return value and handle errors accordingly.

Applied, thanks.

Michal