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>
Reviewed-on: https://review.coreboot.org/29440
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Marshall Dawson <marshalldawson3rd@gmail.com>
This commit is contained in:
Richard Spiegel 2018-11-02 11:14:38 -07:00 committed by Patrick Georgi
parent bc0c364ea3
commit b59c1f4345
1 changed files with 13 additions and 10 deletions

View File

@ -419,8 +419,8 @@ int cbfs_copy_instance(struct cbfs_image *image, struct buffer *dst)
dst_entry = (struct cbfs_file *)( dst_entry = (struct cbfs_file *)(
(uintptr_t)dst_entry + align_up(entry_size, align)); (uintptr_t)dst_entry + align_up(entry_size, align));
if ((size_t)((void *)dst_entry - buffer_get(dst)) >= if ((size_t)((uint8_t *)dst_entry - (uint8_t *)buffer_get(dst))
copy_end) { >= copy_end) {
ERROR("Ran out of room in copy region.\n"); ERROR("Ran out of room in copy region.\n");
return 1; return 1;
} }
@ -430,8 +430,9 @@ int cbfs_copy_instance(struct cbfs_image *image, struct buffer *dst)
* which may be used by the master header pointer. This messes with * which may be used by the master header pointer. This messes with
* the ability to stash something "top-aligned" into the region, but * the ability to stash something "top-aligned" into the region, but
* keeps things simpler. */ * keeps things simpler. */
last_entry_size = copy_end - ((void *)dst_entry - buffer_get(dst)) last_entry_size = copy_end -
- cbfs_calculate_file_header_size("") - sizeof(int32_t); ((uint8_t *)dst_entry - (uint8_t *)buffer_get(dst)) -
cbfs_calculate_file_header_size("") - sizeof(int32_t);
if (last_entry_size < 0) if (last_entry_size < 0)
WARN("No room to create the last entry!\n") WARN("No room to create the last entry!\n")
@ -467,8 +468,9 @@ int cbfs_expand_to_region(struct buffer *region)
* file header. That's either outside the image or exactly the place * file header. That's either outside the image or exactly the place
* where we need to create a new file. * where we need to create a new file.
*/ */
int last_entry_size = region_sz - ((void *)entry - buffer_get(region)) int last_entry_size = region_sz -
- cbfs_calculate_file_header_size("") - sizeof(int32_t); ((uint8_t *)entry - (uint8_t *)buffer_get(region)) -
cbfs_calculate_file_header_size("") - sizeof(int32_t);
if (last_entry_size > 0) { if (last_entry_size > 0) {
cbfs_create_empty_entry(entry, CBFS_COMPONENT_NULL, cbfs_create_empty_entry(entry, CBFS_COMPONENT_NULL,
@ -509,10 +511,10 @@ int cbfs_truncate_space(struct buffer *region, uint32_t *size)
(trailer->type != htonl(CBFS_COMPONENT_DELETED))) { (trailer->type != htonl(CBFS_COMPONENT_DELETED))) {
/* nothing to truncate. Return de-facto CBFS size in case it /* nothing to truncate. Return de-facto CBFS size in case it
* was already truncated. */ * was already truncated. */
*size = (void *)entry - buffer_get(region); *size = (uint8_t *)entry - (uint8_t *)buffer_get(region);
return 0; return 0;
} }
*size = (void *)trailer - buffer_get(region); *size = (uint8_t *)trailer - (uint8_t *)buffer_get(region);
memset(trailer, 0xff, buffer_size(region) - *size); memset(trailer, 0xff, buffer_size(region) - *size);
return 0; return 0;
@ -723,7 +725,8 @@ static int cbfs_add_entry_at(struct cbfs_image *image,
len = addr_next - addr - min_entry_size; len = addr_next - addr - min_entry_size;
/* keep space for master header pointer */ /* keep space for master header pointer */
if ((void *)entry + min_entry_size + len > buffer_get(&image->buffer) + if ((uint8_t *)entry + min_entry_size + len >
(uint8_t *)buffer_get(&image->buffer) +
buffer_size(&image->buffer) - sizeof(int32_t)) { buffer_size(&image->buffer) - sizeof(int32_t)) {
len -= sizeof(int32_t); len -= sizeof(int32_t);
} }