qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] Check fread() results to avoid gcc 4.6 warnings


From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH] Check fread() results to avoid gcc 4.6 warnings
Date: Fri, 05 Aug 2011 11:46:09 -0500
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110516 Lightning/1.0b2 Thunderbird/3.1.10

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<address@hidden>

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) {




reply via email to

[Prev in Thread] Current Thread [Next in Thread]