diff options
author | Patrick Georgi <pgeorgi@chromium.org> | 2016-12-14 16:16:47 +0100 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2016-12-15 22:58:38 +0100 |
commit | 8099803c4657994de6ef02150c99fd178527c80a (patch) | |
tree | 7e41d7dc283faaf6642226174bf60f677699258f /util | |
parent | 6b2d2db9eb514f6c54cf951fe864e052b680edef (diff) | |
download | coreboot-8099803c4657994de6ef02150c99fd178527c80a.tar.xz |
util/cbfstool: Handle error condition more carefully
Change-Id: I72a7776d530d1cf0b8fa39e558990df3dc7f7805
Signed-off-by: Patrick Georgi <pgeorgi@chromium.org>
Found-by: Coverity Scan #1295494
Reviewed-on: https://review.coreboot.org/17861
Reviewed-by: Nico Huber <nico.h@gmx.de>
Tested-by: build bot (Jenkins)
Diffstat (limited to 'util')
-rw-r--r-- | util/cbfstool/common.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c index 3093ba1465..5a47c2f45b 100644 --- a/util/cbfstool/common.c +++ b/util/cbfstool/common.c @@ -71,12 +71,13 @@ int buffer_from_file(struct buffer *buffer, const char *filename) return -1; } buffer->offset = 0; - buffer->size = get_file_size(fp); - if (buffer->size == -1u) { + off_t file_size = get_file_size(fp); + if (file_size < 0) { fprintf(stderr, "could not determine size of %s\n", filename); fclose(fp); return -1; } + buffer->size = file_size; buffer->name = strdup(filename); buffer->data = (char *)malloc(buffer->size); assert(buffer->data); |