summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Spiegel <richard.spiegel@amd.corp-partner.google.com>2018-11-02 11:14:38 -0700
committerPatrick Georgi <pgeorgi@google.com>2018-11-16 09:42:00 +0000
commitb59c1f4345d5528bcec2ede8487f11c04ac4de05 (patch)
tree7b4fab99f47fa3f3c3228cb235fa275ddf6ade76
parentbc0c364ea3ef0332f19fd4a04d81d02c8d72832e (diff)
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>
-rw-r--r--util/cbfstool/cbfs_image.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/util/cbfstool/cbfs_image.c b/util/cbfstool/cbfs_image.c
index 74572a9492..c84eaab48d 100644
--- a/util/cbfstool/cbfs_image.c
+++ b/util/cbfstool/cbfs_image.c
@@ -419,8 +419,8 @@ int cbfs_copy_instance(struct cbfs_image *image, struct buffer *dst)
dst_entry = (struct cbfs_file *)(
(uintptr_t)dst_entry + align_up(entry_size, align));
- if ((size_t)((void *)dst_entry - buffer_get(dst)) >=
- copy_end) {
+ if ((size_t)((uint8_t *)dst_entry - (uint8_t *)buffer_get(dst))
+ >= copy_end) {
ERROR("Ran out of room in copy region.\n");
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
* 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 @@ int cbfs_expand_to_region(struct buffer *region)
* 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,10 @@ int cbfs_truncate_space(struct buffer *region, uint32_t *size)
(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 = (uint8_t *)entry - (uint8_t *)buffer_get(region);
return 0;
}
- *size = (void *)trailer - buffer_get(region);
+ *size = (uint8_t *)trailer - (uint8_t *)buffer_get(region);
memset(trailer, 0xff, buffer_size(region) - *size);
return 0;
@@ -723,8 +725,9 @@ static int cbfs_add_entry_at(struct cbfs_image *image,
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, "");