ao-tools: Use array indexing instead of addition to make gcc-10 happy
authorKeith Packard <keithp@keithp.com>
Fri, 17 Apr 2020 19:51:13 +0000 (12:51 -0700)
committerKeith Packard <keithp@keithp.com>
Fri, 17 Apr 2020 19:54:56 +0000 (12:54 -0700)
A struct with a trailing zero-length array (for variable-length data) is
treated as a zero-sized object when doing pointer arithmetic, but treated
correctly when treated as an array. This generates a warning from gcc-10

load->data + address - load->address

while this, which is 'the same', does not:

&load->data[address - load->address]

Signed-off-by: Keith Packard <keithp@keithp.com>
ao-tools/lib/ao-editaltos.c

index a51b7dbe8a129b2635bf26085edcb5cd1ca19dd6..602390e3d324d7e0cb736d39f25b5b169d63b39d 100644 (file)
@@ -56,7 +56,7 @@ rewrite(struct ao_hex_image *load, unsigned address, uint8_t *data, int length)
        if (address < load->address || load->address + load->length < address + length)
                return false;
 
-       memcpy(load->data + address - load->address, data, length);
+       memcpy(&load->data[address - load->address], data, length);
        return true;
 }