diff options
author | Peter Stuge <peter@stuge.se> | 2009-01-12 21:00:35 +0000 |
---|---|---|
committer | Peter Stuge <peter@stuge.se> | 2009-01-12 21:00:35 +0000 |
commit | 475ac26a9b4f14e35839f6b0df17ea9e81531b74 (patch) | |
tree | 9f684c83dd8623e6d4b8ee8d8bb6a47cece76deb /util/flashrom | |
parent | 6ef8e0f3e3a9044aa326a62e47b71670d9a218b7 (diff) | |
download | coreboot-475ac26a9b4f14e35839f6b0df17ea9e81531b74.tar.xz |
flashrom: Check return value of fscanf()/fwrite()/fread()
Fix build error on distros with warn_unused_result attributes in glibc.
Signed-off-by: Peter Stuge <peter@stuge.se>
Acked-by: Yul Rottmann <yulrottmann@bitel.net>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3857 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'util/flashrom')
-rw-r--r-- | util/flashrom/flashrom.c | 20 | ||||
-rw-r--r-- | util/flashrom/layout.c | 4 |
2 files changed, 15 insertions, 9 deletions
diff --git a/util/flashrom/flashrom.c b/util/flashrom/flashrom.c index 623ce7f05d..9c8db6e6bd 100644 --- a/util/flashrom/flashrom.c +++ b/util/flashrom/flashrom.c @@ -296,7 +296,7 @@ void print_version(void) int main(int argc, char *argv[]) { uint8_t *buf; - unsigned long size; + unsigned long size, numbytes; uint32_t erasedbytes; FILE *image; /* Probe for up to three flash chips. */ @@ -517,11 +517,11 @@ int main(int argc, char *argv[]) exclude_end_position - exclude_start_position); - fwrite(buf, sizeof(char), size, image); + numbytes = fwrite(buf, 1, size, image); fclose(image); - printf("done.\n"); + printf("%s.\n", numbytes == size ? "done" : "FAILED"); free(buf); - exit(0); + return numbytes != size; } // FIXME: flash writes stay enabled! exit(1); @@ -615,9 +615,11 @@ int main(int argc, char *argv[]) memset(buf + exclude_start_position, 0, exclude_end_position - exclude_start_position); - fwrite(buf, sizeof(char), size, image); + numbytes = fwrite(buf, 1, size, image); fclose(image); - printf("done.\n"); + printf("%s.\n", numbytes == size ? "done" : "FAILED"); + if (numbytes != size) + return 1; } else { struct stat image_stat; @@ -634,9 +636,13 @@ int main(int argc, char *argv[]) exit(1); } - fread(buf, sizeof(char), size, image); + numbytes = fread(buf, 1, size, image); show_id(buf, size, force); fclose(image); + if (numbytes != size) { + fprintf(stderr, "Error: Failed to read file. Got %ld bytes, wanted %ld!\n", numbytes, size); + return 1; + } } /* exclude range stuff. Nice idea, but at the moment it is only diff --git a/util/flashrom/layout.c b/util/flashrom/layout.c index e2be12e9a9..84a8ec7052 100644 --- a/util/flashrom/layout.c +++ b/util/flashrom/layout.c @@ -146,8 +146,8 @@ int read_romlayout(char *name) while (!feof(romlayout)) { char *tstr1, *tstr2; - fscanf(romlayout, "%s %s\n", tempstr, - rom_entries[romimages].name); + if (2 != fscanf(romlayout, "%s %s\n", tempstr, rom_entries[romimages].name)) + continue; #if 0 // fscanf does not like arbitrary comments like that :( later if (tempstr[0] == '#') { |