summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util/cbfstool/common.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c
index ea22bd6460..8ae9120acc 100644
--- a/util/cbfstool/common.c
+++ b/util/cbfstool/common.c
@@ -46,17 +46,17 @@ int buffer_from_file_aligned_size(struct buffer *buffer, const char *filename,
perror(filename);
return -1;
}
- buffer->offset = 0;
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 = ALIGN_UP(file_size, size_granularity);
- buffer->name = strdup(filename);
- buffer->data = (char *)malloc(buffer->size);
- assert(buffer->data);
+ if (buffer_create(buffer, ALIGN_UP(file_size, size_granularity), filename)) {
+ fprintf(stderr, "could not allocate buffer\n");
+ fclose(fp);
+ return -1;
+ }
if (fread(buffer->data, 1, file_size, fp) != (size_t)file_size) {
fprintf(stderr, "incomplete read: %s\n", filename);
fclose(fp);