Cast `void *` to something before doing arithmetic on it

This commit is contained in:
Ben Edgington 2021-02-20 15:25:55 +00:00
parent 3dbcfa2a97
commit 7fd0899972
1 changed files with 5 additions and 3 deletions

View File

@ -91,15 +91,17 @@ C_KZG_RET reverse_bit_order(void *values, size_t size, uint64_t n) {
CHECK(n >> 32 == 0); CHECK(n >> 32 == 0);
CHECK(is_power_of_two(n)); CHECK(is_power_of_two(n));
// Pointer arithmetic on `void *` is naughty, so cast to something definite
byte *v = values;
byte tmp[size]; byte tmp[size];
int unused_bit_len = 32 - log2_pow2(n); int unused_bit_len = 32 - log2_pow2(n);
for (uint32_t i = 0; i < n; i++) { for (uint32_t i = 0; i < n; i++) {
uint32_t r = reverse_bits(i) >> unused_bit_len; uint32_t r = reverse_bits(i) >> unused_bit_len;
if (r > i) { if (r > i) {
// Swap the two elements // Swap the two elements
memcpy(tmp, values + (i * size), size); memcpy(tmp, v + (i * size), size);
memcpy(values + (i * size), values + (r * size), size); memcpy(v + (i * size), v + (r * size), size);
memcpy(values + (r * size), tmp, size); memcpy(v + (r * size), tmp, size);
} }
} }