Skip to contentSkip to conversation

x86: Fix warning: ignoring return value of 'fread'

PATCH In review Jean Sacren 2 participants 3 messages Aug 26, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover x86: Fix warning: ignoring return value of 'fread'

Hi,

Jean Sacren (1):
x86: Fix warning: ignoring return value of 'fread'

 arch/x86/boot/compressed/mkpiggy.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
Signature · 2 lines
Jean Sacren
Bring LAMP To People
#1 lore raw

PATCH 1/1 x86: Fix warning: ignoring return value of 'fread'

warning: ignoring return value of 'fread', declared with attribute warn_unused_result

This fix facilitates fread() either it succeeds, or an error occurs or the end of file is reached.

---
 arch/x86/boot/compressed/mkpiggy.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
arch/x86/boot/compressed/mkpiggy.c +4 -1
index 5c22812..fac37c3 100644
@@ -62,7 +62,10 @@ int main(int argc, char *argv[])
 	if (fseek(f, -4L, SEEK_END)) {
 		perror(argv[1]);
 	}
-	fread(&olen, sizeof olen, 1, f);
+
+	if (fread(&olen, sizeof olen, 1, f) < 1)
+		fprintf(stderr, "\nError in reading or end of file.\n");
+
 	ilen = ftell(f);
 	olen = getle32(&olen);
 	fclose(f);
Signature · 1 line
1.7.1
#2 lore raw
Quoted 17 lines · Jean Sacren

warning: ignoring return value of 'fread', declared with attribute warn_unused_result

This fix facilitates fread() either it succeeds, or an error occurs or the end of file is reached.

---
 arch/x86/boot/compressed/mkpiggy.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
arch/x86/boot/compressed/mkpiggy.c +0 -0
index 5c22812..fac37c3 100644
@@ -62,7 +62,10 @@ int main(int argc, char *argv[])
 	if (fseek(f, -4L, SEEK_END)) {

arch/x86/boot/compressed/mkpiggy.c int main(int argc, char *argv[]) · line 71

Quoted 10 lines
arch/x86/boot/compressed/mkpiggy.c +4 -1
 		perror(argv[1]);
 	}
-	fread(&olen, sizeof olen, 1, f);
+
+	if (fread(&olen, sizeof olen, 1, f) < 1)
+		fprintf(stderr, "\nError in reading or end of file.\n");
+
 	ilen = ftell(f);
 	olen = getle32(&olen);
 	fclose(f);

I usually prefer the style:

if (fread(&olen, 1, sizeof olen, f) != sizeof olen)

... for consistency with plain write(). It's a minor nitpick, though.

-hpa