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)
This commit is contained in:
parent
6b2d2db9eb
commit
8099803c46
|
@ -71,12 +71,13 @@ int buffer_from_file(struct buffer *buffer, const char *filename)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
buffer->offset = 0;
|
buffer->offset = 0;
|
||||||
buffer->size = get_file_size(fp);
|
off_t file_size = get_file_size(fp);
|
||||||
if (buffer->size == -1u) {
|
if (file_size < 0) {
|
||||||
fprintf(stderr, "could not determine size of %s\n", filename);
|
fprintf(stderr, "could not determine size of %s\n", filename);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
buffer->size = file_size;
|
||||||
buffer->name = strdup(filename);
|
buffer->name = strdup(filename);
|
||||||
buffer->data = (char *)malloc(buffer->size);
|
buffer->data = (char *)malloc(buffer->size);
|
||||||
assert(buffer->data);
|
assert(buffer->data);
|
||||||
|
|
Loading…
Reference in New Issue