x86: Fix warning: ignoring return value of 'fread'
Subsystems (2)
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
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
@@ -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
Quoted 17 lines · Jean Sacren
warning: ignoring return value of 'fread', declared with attribute
warn_unused_resultThis fix facilitates
fread()either it succeeds, or an error occurs or the end of file is reached.Signed-off-by Jean Sacren <[email protected]>--- arch/x86/boot/compressed/mkpiggy.c | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)arch/x86/boot/compressed/mkpiggy.c +0
-0@@ -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
-1perror (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