On 10 March 2014 19:56, Michael S. Tsirkin <m...@redhat.com> wrote: > casting an unaligned address to e.g. > uint32_t can trigger undefined behaviour in C. > Replace cast + assignment with memcpy. > > Reported-by: Peter Maydell <peter.mayd...@linaro.org> > Signed-off-by: Michael S. Tsirkin <m...@redhat.com>
This does fix the clang warnings. > -/* Get pointer within table in a safe manner */ > -#define ACPI_BUILD_PTR(table, size, off, type) \ > - ((type *)(acpi_data_get_ptr(table, size, off, sizeof(type)))) > +/* Set a value within table in a safe manner */ > +#define ACPI_BUILD_SET_LE(table, size, off, bits, val) \ > + do { \ > + uint64_t ACPI_BUILD_SET_LE_val = cpu_to_le64(val); \ > + memcpy(acpi_data_get_ptr(table, size, off, \ > + (bits) / BITS_PER_BYTE), \ > + &ACPI_BUILD_SET_LE_val, \ > + (bits) / BITS_PER_BYTE); \ > + } while (0) Personally I would have done: #define acpi_stb(table, size, off, val) \ stb_le_p(acpi_data_get_ptr(table, size, off, 1), val) #define acpi_stw(table, size, off, val) \ stw_le_p(acpi_data_get_ptr(table, size, off, 2), val) #define acpi_stl(table, size, off, val) \ stl_le_p(acpi_data_get_ptr(table, size, off, 4), val) #define acpi_stq(table, size, off, val) \ stq_le_p(acpi_data_get_ptr(table, size, off, 8), val) which keeps the grubby details of memcpy and byteswapping in bswap.h. However since it's purely inside this file and not specifying an API to the rest of QEMU I don't object if you prefer the approach you've taken. thanks -- PMM