Richard Spiegel has uploaded this change for review. ( https://review.coreboot.org/29440
Change subject: util/cbfstool/cbfs_image.c: Get rid of void pointer math ......................................................................
util/cbfstool/cbfs_image.c: Get rid of void pointer math
Pointer math with void pointers is illegal in many compilers, though it works with GCC because it assumes size of void to be 1. Change the pointers or add parenthesis to force a proper order that will not cause compile errors if compiled with a different compiler, and more importantly, don't have unsuspected side effects.
BUG=b:118484178 TEST=Build CBFS with original code, run objdump and saved output. Added modifications, build cbfs again, run objdump again, compared objdump outputs.
Change-Id: I30187de8ea24adba41083f3bfbd24c0e363ee4b8 Signed-off-by: Richard Spiegel richard.spiegel@silverbackltd.com --- M util/cbfstool/cbfs_image.c 1 file changed, 12 insertions(+), 8 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/40/29440/1
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c index 74572a9..2160742 100644 --- a/util/cbfstool/cbfs_image.c +++ b/util/cbfstool/cbfs_image.c @@ -430,8 +430,9 @@ * which may be used by the master header pointer. This messes with * the ability to stash something "top-aligned" into the region, but * keeps things simpler. */ - last_entry_size = copy_end - ((void *)dst_entry - buffer_get(dst)) - - cbfs_calculate_file_header_size("") - sizeof(int32_t); + last_entry_size = copy_end - + ((uint8_t *)dst_entry - (uint8_t *)buffer_get(dst)) - + cbfs_calculate_file_header_size("") - sizeof(int32_t);
if (last_entry_size < 0) WARN("No room to create the last entry!\n") @@ -467,8 +468,9 @@ * file header. That's either outside the image or exactly the place * where we need to create a new file. */ - int last_entry_size = region_sz - ((void *)entry - buffer_get(region)) - - cbfs_calculate_file_header_size("") - sizeof(int32_t); + int last_entry_size = region_sz - + ((uint8_t *)entry - (uint8_t *)buffer_get(region)) - + cbfs_calculate_file_header_size("") - sizeof(int32_t);
if (last_entry_size > 0) { cbfs_create_empty_entry(entry, CBFS_COMPONENT_NULL, @@ -509,10 +511,11 @@ (trailer->type != htonl(CBFS_COMPONENT_DELETED))) { /* nothing to truncate. Return de-facto CBFS size in case it * was already truncated. */ - *size = (void *)entry - buffer_get(region); + *size = (uint32_t)((uint8_t *)entry - + (uint8_t *)buffer_get(region)); return 0; } - *size = (void *)trailer - buffer_get(region); + *size = (uint32_t)((uint8_t *)trailer - (uint8_t *)buffer_get(region)); memset(trailer, 0xff, buffer_size(region) - *size);
return 0; @@ -723,8 +726,9 @@
len = addr_next - addr - min_entry_size; /* keep space for master header pointer */ - if ((void *)entry + min_entry_size + len > buffer_get(&image->buffer) + - buffer_size(&image->buffer) - sizeof(int32_t)) { + if (((uint8_t *)entry + min_entry_size + len) > + ((uint8_t *)buffer_get(&image->buffer) + + buffer_size(&image->buffer) - sizeof(int32_t))) { len -= sizeof(int32_t); } cbfs_create_empty_entry(entry, CBFS_COMPONENT_NULL, len, "");