From a33a3f4ff8bca72b27a193b39debed0327c3a551 Mon Sep 17 00:00:00 2001 From: "Matwey V. Kornilov" <matwey.kornilov@gmail.com> Date: Fri, 29 Nov 2024 21:09:39 +0300 Subject: [PATCH] Fix unaligned memory access in tests/genicam.c Currently, this function leads to SIGBUS crash at armv7l architecture without CONFIG_ALIGNMENT_TRAP kernel option. --- tests/genicam.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/genicam.c b/tests/genicam.c index 493fbc2b7..2c6b69bf8 100644 --- a/tests/genicam.c +++ b/tests/genicam.c @@ -1086,10 +1086,10 @@ create_buffer_with_chunk_data (void) ArvChunkInfos *chunk_infos; char *data; size_t size; - guint32 *int_value; + guint32 int_value; guint8 *boolean_value; guint offset; - guint64 *float_value; + guint64 float_value; size = 64 + 8 + 64 + 8 + 1 + 5 * sizeof (ArvChunkInfos); @@ -1107,8 +1107,8 @@ create_buffer_with_chunk_data (void) chunk_infos->id = GUINT32_TO_BE (0x12345678); chunk_infos->size = GUINT32_TO_BE (8); - int_value = (guint32 *) &data[offset - 8]; - *int_value = GUINT32_TO_BE (0x11223344); + int_value = GUINT32_TO_BE (0x11223344); + memcpy ((char *) &data[offset - 8], (char *)&int_value, sizeof(int_value)); offset -= 8 + sizeof (ArvChunkInfos); chunk_infos = (ArvChunkInfos *) &data[offset]; @@ -1122,8 +1122,8 @@ create_buffer_with_chunk_data (void) chunk_infos->id = GUINT32_TO_BE (0x12345679); chunk_infos->size = GUINT32_TO_BE (8); - float_value = (guint64 *) &data[offset - 8]; - *float_value = GUINT64_TO_BE (0x3FF199999999999A); /* Hexadecimal representation of 1.1 as double */ + float_value = GUINT64_TO_BE (0x3FF199999999999A); /* Hexadecimal representation of 1.1 as double */ + memcpy ((char *) &data[offset - 8], (char *)&float_value, sizeof(float_value)); offset -= 8 + sizeof (ArvChunkInfos); chunk_infos = (ArvChunkInfos *) &data[offset];