Check fread() results to avoid gcc 4.6 warnings
PATCH 1/1 Check fread() results to avoid gcc 4.6 warnings
When compiling with gcc 4.6, some code in fw_cfg.c complains that fop_ret is assigned but not used (which is true). However, it looks like the meaningless assignments to fop_ret were done to suppress other gcc warnings due to the fact that fread() is labelled as warn_unused_result in glibc.
This patch avoids both errors, by actually checking the fread() result code and dropping out with an error message if it fails.
--- hw/fw_cfg.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)
hw/fw_cfg.c +13 -0
@@ -87,6 +87,13 @@ static FILE *probe_splashfile(char *filename, int *file_sizep, int *file_typep)/* check magic ID */ fseek (fp,0L ,SEEK_SET ); fop_ret =fread (buf,1 ,2 , fp); +if (fop_ret !=2 ) { +error_report ("Could not read header from '%s': %s" , + filename,strerror (errno)); +fclose (fp); + fp =NULL ; +return fp; + } filehead_value = (buf[0 ] + (buf[1 ] <<8 )) &0xffff ;if (filehead_value ==0xd8ff ) { file_type =JPG_FILE ;
@@ -181,6 +188,12 @@ static void fw_cfg_bootsplash(FWCfgState *s) boot_splash_filedata_size = file_size;fseek (fp,0L ,SEEK_SET ); fop_ret =fread (boot_splash_filedata,1 , file_size, fp); +if (fop_ret != file_size) { +error_report ("failed to read data from '%s'." , + boot_splash_filename); +fclose (fp); +return ; + }fclose (fp);/* insert data */ if (file_type ==JPG_FILE ) {
Signature · 1 line
1.7.5.4
Quoted 5 lines · David Gibson
When compiling with gcc 4.6, some code in
fw_cfg.ccomplains thatfop_retis assigned but not used (which is true). However, it looks like the meaningless assignments tofop_retwere done to suppress other gcc warnings due to the fact thatfread()is labelled aswarn_unused_resultin glibc.
Quoted 7 lines
This patch avoids both errors, by actually checking the
fread()result code and dropping out with an error message if it fails.Signed-off-by David Gibson <[email protected]>---
hw/fw_cfg.c | 13 +++++++++++++1 files changed, 13 insertions(+), 0 deletions(-)
Quoted 10 lines · Stefan Hajnoczi
Quoted 8 lines · David Gibson
When compiling with gcc 4.6, some code in
fw_cfg.ccomplains thatfop_retis assigned but not used (which is true). However, it looks like the meaningless assignments tofop_retwere done to suppress other gcc warnings due to the fact thatfread()is labelled aswarn_unused_resultin glibc.This patch avoids both errors, by actually checking the
fread()result code and dropping out with an error message if it fails.
Quoted 6 lines
Quoted 4 lines
Signed-off-by David Gibson <[email protected]>---
hw/fw_cfg.c | 13 +++++++++++++1 files changed, 13 insertions(+), 0 deletions(-)Reviewed-by Stefan Hajnoczi <[email protected]>
I'm not taking this into the trivial-patches tree because a build fix like this should be merged sooner. With trivial-patches I only send one pull request per week and in the meantime people would have to ./configure --disable-werror which isn't good.
Stefan
Stefan Berger
Tested-byQuoted 7 lines · Stefan Hajnoczi
Quoted 5 lines · David Gibson
When compiling with gcc 4.6, some code in
fw_cfg.ccomplains thatfop_retis assigned but not used (which is true). However, it looks like the meaningless assignments tofop_retwere done to suppress other gcc warnings due to the fact thatfread()is labelled aswarn_unused_resultin glibc.
Quoted 9 lines
Quoted 7 lines
This patch avoids both errors, by actually checking the
fread()result code and dropping out with an error message if it fails.Signed-off-by David Gibson<[email protected]>--- hw/fw_cfg.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)Reviewed-by Stefan Hajnoczi<[email protected]>
Anthony Liguori
AppliedQuoted 9 lines · David Gibson
When compiling with gcc 4.6, some code in
fw_cfg.ccomplains thatfop_retis assigned but not used (which is true). However, it looks like the meaningless assignments tofop_retwere done to suppress other gcc warnings due to the fact thatfread()is labelled aswarn_unused_resultin glibc.This patch avoids both errors, by actually checking the
fread()result code and dropping out with an error message if it fails.Signed-off-by David Gibson<[email protected]>
Applied. Thanks.
Regards,
Anthony Liguori
Quoted 35 lines
--- hw/fw_cfg.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-)hw/fw_cfg.c +13
-0@@ -87,6 +87,13 @@ static FILE *probe_splashfile(char *filename, int *file_sizep, int *file_typep)/* check magic ID */ fseek (fp,0L ,SEEK_SET ); fop_ret =fread (buf,1 ,2 , fp); +if (fop_ret !=2 ) { +error_report ("Could not read header from '%s': %s" , + filename,strerror (errno)); +fclose (fp); + fp =NULL ; +return fp; + } filehead_value = (buf[0 ] + (buf[1 ]<<8 ))&0xffff ;if (filehead_value ==0xd8ff ) { file_type =JPG_FILE ;@@ -181,6 +188,12 @@ static void fw_cfg_bootsplash(FWCfgState *s) boot_splash_filedata_size = file_size;fseek (fp,0L ,SEEK_SET ); fop_ret =fread (boot_splash_filedata,1 , file_size, fp); +if (fop_ret != file_size) { +error_report ("failed to read data from '%s'." , + boot_splash_filename); +fclose (fp); +return ; + }fclose (fp);/* insert data */ if (file_type ==JPG_FILE ) {