Avoid pointer arithmetic on void *

The pointer operand to the binary `+` operator must be to a complete
object type. Since we are working with byte sizes, use `char *` for
arithmetic instead.

Signed-off-by: Michael Forney <mforney@mforney.org>
This commit is contained in:
Michael Forney 2019-06-01 15:01:23 -07:00 committed by Simon Ser
parent 55d044810c
commit 678c8681e2
2 changed files with 4 additions and 6 deletions

View file

@ -131,7 +131,7 @@ wl_array_add(struct wl_array *array, size_t size)
array->alloc = alloc; array->alloc = alloc;
} }
p = array->data + array->size; p = (char *)array->data + array->size;
array->size += size; array->size += size;
return p; return p;

View file

@ -87,8 +87,7 @@ TEST(array_add)
/* verify the data */ /* verify the data */
for (i = 0; i < iterations; ++i) { for (i = 0; i < iterations; ++i) {
const int index = datasize * i; struct mydata* check = (struct mydata*)array.data + i;
struct mydata* check = (struct mydata*)(array.data + index);
assert(check->a == i * 3); assert(check->a == i * 3);
assert(check->b == 20000 - i); assert(check->b == 20000 - i);
@ -121,9 +120,8 @@ TEST(array_copy)
/* check the copy */ /* check the copy */
for (i = 0; i < iterations; i++) { for (i = 0; i < iterations; i++) {
const int index = sizeof(int) * i; int *s = (int *)source.data + i;
int *s = (int *)(source.data + index); int *c = (int *)copy.data + i;
int *c = (int *)(copy.data + index);
assert(*s == *c); /* verify the values are the same */ assert(*s == *c); /* verify the values are the same */
assert(s != c); /* ensure the addresses aren't the same */ assert(s != c); /* ensure the addresses aren't the same */