qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Check fread() results to avoid gcc 4.6 warnings
@ 2011-08-01  6:49 David Gibson
  2011-08-01 10:19 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
  2011-08-05 16:46 ` [Qemu-devel] " Anthony Liguori
  0 siblings, 2 replies; 5+ messages in thread
From: David Gibson @ 2011-08-01  6:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-trivial

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.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 hw/fw_cfg.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index a29db90..e4847b7 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -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) {
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH] Check fread() results to avoid gcc 4.6 warnings
  2011-08-01  6:49 [Qemu-devel] [PATCH] Check fread() results to avoid gcc 4.6 warnings David Gibson
@ 2011-08-01 10:19 ` Stefan Hajnoczi
  2011-08-03 10:15   ` Stefan Hajnoczi
  2011-08-03 13:46   ` Stefan Berger
  2011-08-05 16:46 ` [Qemu-devel] " Anthony Liguori
  1 sibling, 2 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2011-08-01 10:19 UTC (permalink / raw)
  To: David Gibson; +Cc: qemu-trivial, qemu-devel

On Mon, Aug 1, 2011 at 7:49 AM, David Gibson
<david@gibson.dropbear.id.au> wrote:
> 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.
>
> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> ---
>  hw/fw_cfg.c |   13 +++++++++++++
>  1 files changed, 13 insertions(+), 0 deletions(-)

Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH] Check fread() results to avoid gcc 4.6 warnings
  2011-08-01 10:19 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
@ 2011-08-03 10:15   ` Stefan Hajnoczi
  2011-08-03 13:46   ` Stefan Berger
  1 sibling, 0 replies; 5+ messages in thread
From: Stefan Hajnoczi @ 2011-08-03 10:15 UTC (permalink / raw)
  To: David Gibson; +Cc: qemu-trivial, qemu-devel

On Mon, Aug 01, 2011 at 11:19:38AM +0100, Stefan Hajnoczi wrote:
> On Mon, Aug 1, 2011 at 7:49 AM, David Gibson
> <david@gibson.dropbear.id.au> wrote:
> > 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.
> >
> > Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
> > ---
> >  hw/fw_cfg.c |   13 +++++++++++++
> >  1 files changed, 13 insertions(+), 0 deletions(-)
> 
> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [Qemu-trivial] [PATCH] Check fread() results to avoid gcc 4.6 warnings
  2011-08-01 10:19 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
  2011-08-03 10:15   ` Stefan Hajnoczi
@ 2011-08-03 13:46   ` Stefan Berger
  1 sibling, 0 replies; 5+ messages in thread
From: Stefan Berger @ 2011-08-03 13:46 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-trivial, qemu-devel, David Gibson

On 08/01/2011 06:19 AM, Stefan Hajnoczi wrote:
> On Mon, Aug 1, 2011 at 7:49 AM, David Gibson
> <david@gibson.dropbear.id.au>  wrote:
>> 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.
>>
>> Signed-off-by: David Gibson<david@gibson.dropbear.id.au>
>> ---
>>   hw/fw_cfg.c |   13 +++++++++++++
>>   1 files changed, 13 insertions(+), 0 deletions(-)
> Reviewed-by: Stefan Hajnoczi<stefanha@linux.vnet.ibm.com>
>
Tested-by: Stefan Berger <stefanb@linux.vnet.ibm.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] Check fread() results to avoid gcc 4.6 warnings
  2011-08-01  6:49 [Qemu-devel] [PATCH] Check fread() results to avoid gcc 4.6 warnings David Gibson
  2011-08-01 10:19 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
@ 2011-08-05 16:46 ` Anthony Liguori
  1 sibling, 0 replies; 5+ messages in thread
From: Anthony Liguori @ 2011-08-05 16:46 UTC (permalink / raw)
  To: David Gibson; +Cc: qemu-trivial, qemu-devel

On 08/01/2011 01:49 AM, David Gibson wrote:
> 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.
>
> Signed-off-by: David Gibson<david@gibson.dropbear.id.au>

Applied.  Thanks.

Regards,

Anthony Liguori

> ---
>   hw/fw_cfg.c |   13 +++++++++++++
>   1 files changed, 13 insertions(+), 0 deletions(-)
>
> diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
> index a29db90..e4847b7 100644
> --- a/hw/fw_cfg.c
> +++ b/hw/fw_cfg.c
> @@ -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) {

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-08-05 16:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-01  6:49 [Qemu-devel] [PATCH] Check fread() results to avoid gcc 4.6 warnings David Gibson
2011-08-01 10:19 ` [Qemu-devel] [Qemu-trivial] " Stefan Hajnoczi
2011-08-03 10:15   ` Stefan Hajnoczi
2011-08-03 13:46   ` Stefan Berger
2011-08-05 16:46 ` [Qemu-devel] " Anthony Liguori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).