From 70461a9524fc84ec5c095f11927cffa0429a6267 Mon Sep 17 00:00:00 2001 From: Nico Huber Date: Sat, 15 Jun 2019 14:56:19 +0200 Subject: layout: Make `romentry.name` a pointer This should provide more flexibility while we don't have to allocate 256B extra per layout entry. Change-Id: Ibb903113550ec13f43cbbd0a412c8f35fe1cf454 Signed-off-by: Nico Huber Reviewed-on: https://review.coreboot.org/c/flashrom/+/33515 Tested-by: build bot (Jenkins) Reviewed-by: Arthur Heymans --- libflashrom.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'libflashrom.c') diff --git a/libflashrom.c b/libflashrom.c index 721a11cf..af62002a 100644 --- a/libflashrom.c +++ b/libflashrom.c @@ -20,6 +20,7 @@ * Have a look at the Modules section for a function reference. */ +#include #include #include #include @@ -384,9 +385,12 @@ static int flashrom_layout_parse_fmap(struct flashrom_layout **layout, l->entries[l->num_entries].start = fmap->areas[i].offset; l->entries[l->num_entries].end = fmap->areas[i].offset + fmap->areas[i].size - 1; l->entries[l->num_entries].included = false; - memset(l->entries[l->num_entries].name, 0, sizeof(l->entries[i].name)); - memcpy(l->entries[l->num_entries].name, fmap->areas[i].name, - min(FMAP_STRLEN, sizeof(l->entries[i].name))); + l->entries[l->num_entries].name = + strndup((const char *)fmap->areas[i].name, FMAP_STRLEN); + if (!l->entries[l->num_entries].name) { + msg_gerr("Error adding layout entry: %s\n", strerror(errno)); + return 1; + } msg_gdbg("fmap %08x - %08x named %s\n", l->entries[l->num_entries].start, l->entries[l->num_entries].end, -- cgit v1.2.3