[PATCH] lib: fwts_coreboot_cbmem: don't use void * pointer arithmetic

Colin King colin.king at canonical.com
Tue Nov 13 12:40:13 UTC 2018


From: Colin Ian King <colin.king at canonical.com>

void * pointer arithmetic is a GCC'ism and the behaviour is undefined,
so use char * pointer arithmetic instead. Cleans up clang warnings.

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/lib/src/fwts_coreboot_cbmem.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/src/lib/src/fwts_coreboot_cbmem.c b/src/lib/src/fwts_coreboot_cbmem.c
index 53e57136..e02c523c 100644
--- a/src/lib/src/fwts_coreboot_cbmem.c
+++ b/src/lib/src/fwts_coreboot_cbmem.c
@@ -144,11 +144,11 @@ static int parse_cbtable_entries(
 	off_t *cbmem_console_addr)
 {
 	size_t i;
-	const struct lb_record* lbr_p;
 	int forwarding_table_found = 0;
+	const struct lb_record *lbr_p;
 
 	for (i = 0; i < table_size; i += lbr_p->size) {
-		lbr_p = lbtable + i;
+		lbr_p = (struct lb_record*)((char *)lbtable + i);
 		switch (lbr_p->tag) {
 		case LB_TAG_CBMEM_CONSOLE: {
 			*cbmem_console_addr = (off_t)parse_cbmem_ref((const struct lb_cbmem_ref *) lbr_p).cbmem_addr;
@@ -205,11 +205,9 @@ static int parse_cbtable(
 	/* look at every 16 bytes */
 	for (i = 0; i <= req_size - sizeof(struct lb_header); i += 16) {
 		int ret;
-		const struct lb_header *lbh;
+		const struct lb_header *lbh = (struct lb_header *)((char *)buf + i);
 		void *map;
 
-		lbh = buf + i;
-
 		if (memcmp(lbh->signature, "LBIO", sizeof(lbh->signature)) ||
 		    !lbh->header_bytes ||
 		    ipchcksum(lbh, sizeof(*lbh))) {
@@ -262,7 +260,7 @@ static ssize_t memory_read_from_buffer(
 	if (count > available - pos)
 		count = available - pos;
 
-	memcpy(to, from + pos, count);
+	memcpy(to, (char *)from + pos, count);
 
 	*ppos = pos + count;
 
-- 
2.19.1




More information about the fwts-devel mailing list