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 | 1fec0f35c70bede4c9d54e3007f609611b354f1e (patch) | |
tree | 76d5371b6a5d6eaa6e0600a8e3d5a5cdcf98554b /flashrom.c | |
parent | 4cf3eefb84138f8b1f2578915520a4aff73dd92f (diff) | |
download | flashrom-1fec0f35c70bede4c9d54e3007f609611b354f1e.tar.gz flashrom-1fec0f35c70bede4c9d54e3007f609611b354f1e.tar.bz2 flashrom-1fec0f35c70bede4c9d54e3007f609611b354f1e.zip |
Check return value of fscanf()/fwrite()/fread()
Fix build error on distros with warn_unused_result attributes in glibc.
Corresponding to flashrom svn r378 and coreboot v2 svn r3857.
Signed-off-by: Peter Stuge <peter@stuge.se>
Acked-by: Yul Rottmann <yulrottmann@bitel.net>
Diffstat (limited to 'flashrom.c')
-rw-r--r-- | flashrom.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/flashrom.c b/flashrom.c index 623ce7f05..9c8db6e6b 100644 --- a/flashrom.c +++ b/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 |