Skip to contentSkip to conversation

dtc: Check return value from fwrite()

PATCH Applied David Gibson 2 participants 2 messages Nov 7, 2008 – Nov 17, 2008 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

There's one place in flattree.c where we currently ignore the return value from fwrite(). On some gcc/glibc versions, where fwrite() is declared with attribute warn_unused_result, this causes a warning.

This patch fixes the warning, by checking the fwrite() result.

flattree.c +7 -4
Index: dtc/flattree.c
===================================================================
@@ -413,10 +413,13 @@ void dt_to_blob(FILE *f, struct boot_inf
 	if (padlen > 0)
 		blob = data_append_zeroes(blob, padlen);
 
-	fwrite(blob.val, blob.len, 1, f);
-
-	if (ferror(f))
-		die("Error writing device tree blob: %s\n", strerror(errno));
+	if (fwrite(blob.val, blob.len, 1, f) != 1) {
+		if (ferror(f))
+			die("Error writing device tree blob: %s\n",
+			    strerror(errno));
+		else
+			die("Short write on device tree blob\n");
+	}
 
 	/*
 	 * data_merge() frees the right-hand element so only the blob
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

A message that is not in the archive (sent off-list or not yet received): [email protected]

Applied
#2 lore raw
Quoted 7 lines

There's one place in flattree.c where we currently ignore the return value from fwrite(). On some gcc/glibc versions, where fwrite() is declared with attribute warn_unused_result, this causes a warning.

This patch fixes the warning, by checking the fwrite() result.

Applied.

Thanks,
jdl