From: "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] fw_cfg: Simplify error paths and avoid warnings
Date: Fri, 5 Aug 2011 00:26:38 +0200 [thread overview]
Message-ID: <20110804222638.GB2601@zapo> (raw)
master branch doesnt build due to 3d3b8303c6f83b9b245bc774af530a6403cc4ce6
hw/fw_cfg.c: In function ‘probe_splashfile’:
hw/fw_cfg.c:66:9: error: variable ‘fop_ret’ set but not used [-Werror=unused-but-set-variable]
hw/fw_cfg.c: In function ‘fw_cfg_bootsplash’:
hw/fw_cfg.c:130:9: error: variable ‘fop_ret’ set but not used [-Werror=unused-but-set-variable]
This is a basically untested fix, compile tested only.
Cheers
---
commit fb4515b04705414ab9ea9d5deb4728b41525761e
Author: Edgar E. Iglesias <edgar.iglesias@gmail.com>
Date: Thu Aug 4 01:17:16 2011 +0200
fw_cfg: Simplify error paths and avoid warnings
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@gmail.com>
diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c
index a29db90..8593c25 100644
--- a/hw/fw_cfg.c
+++ b/hw/fw_cfg.c
@@ -80,13 +80,15 @@ static FILE *probe_splashfile(char *filename, int *file_sizep, int *file_typep)
file_size = ftell(fp);
if (file_size < 2) {
error_report("file size is less than 2 bytes '%s'.", filename);
- fclose(fp);
- fp = NULL;
- return fp;
+ goto fail;
}
/* check magic ID */
fseek(fp, 0L, SEEK_SET);
fop_ret = fread(buf, 1, 2, fp);
+ if (fop_ret != 2) {
+ goto fail;
+ }
+
filehead_value = (buf[0] + (buf[1] << 8)) & 0xffff;
if (filehead_value == 0xd8ff) {
file_type = JPG_FILE;
@@ -98,9 +100,7 @@ static FILE *probe_splashfile(char *filename, int *file_sizep, int *file_typep)
if (file_type < 0) {
error_report("'%s' not jpg/bmp file,head:0x%x.",
filename, filehead_value);
- fclose(fp);
- fp = NULL;
- return fp;
+ goto fail;
}
/* check BMP bpp */
if (file_type == BMP_FILE) {
@@ -109,15 +109,17 @@ static FILE *probe_splashfile(char *filename, int *file_sizep, int *file_typep)
bmp_bpp = (buf[0] + (buf[1] << 8)) & 0xffff;
if (bmp_bpp != 24) {
error_report("only 24bpp bmp file is supported.");
- fclose(fp);
- fp = NULL;
- return fp;
+ goto fail;
}
}
/* return values */
*file_sizep = file_size;
*file_typep = file_type;
return fp;
+
+fail:
+ fclose(fp);
+ return NULL;
}
static void fw_cfg_bootsplash(FWCfgState *s)
@@ -169,8 +171,8 @@ static void fw_cfg_bootsplash(FWCfgState *s)
}
/* probing the file */
fp = probe_splashfile(filename, &file_size, &file_type);
+ qemu_free(filename);
if (fp == NULL) {
- qemu_free(filename);
return;
}
/* loading file data */
@@ -182,6 +184,10 @@ static void fw_cfg_bootsplash(FWCfgState *s)
fseek(fp, 0L, SEEK_SET);
fop_ret = fread(boot_splash_filedata, 1, file_size, fp);
fclose(fp);
+ if (fop_ret != file_size) {
+ return;
+ }
+
/* insert data */
if (file_type == JPG_FILE) {
fw_cfg_add_file(s, "bootsplash.jpg",
@@ -190,7 +196,6 @@ static void fw_cfg_bootsplash(FWCfgState *s)
fw_cfg_add_file(s, "bootsplash.bmp",
boot_splash_filedata, boot_splash_filedata_size);
}
- qemu_free(filename);
}
}
reply other threads:[~2011-08-04 22:26 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110804222638.GB2601@zapo \
--to=edgar.iglesias@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).