core: make bt_uuid_hash() portable across archs
authorBrian Gix <brian.gix@intel.com>
Wed, 29 Jun 2022 21:16:39 +0000 (14:16 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:54 +0000 (14:55 +0530)
bt_uuid_t is defined as a byte array, so it can cause alignment errors
on some architectures, when the two 64 bit halves are treated as u64s.
This patch ensures proper alignment across all architectures.

Fixes:
src/adapter.c: In function ‘bt_uuid_hash’:
src/adapter.c:3617:8: error: cast increases required alignment of
target type [-Werror=cast-align]
  val = (uint64_t *)&uuid_128.value.u128;
        ^
cc1: all warnings being treated as errors

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
src/adapter.c

index f70ad50..6ec6ce2 100644 (file)
@@ -7948,16 +7948,14 @@ static void add_uuid_to_uuid_set(void *data, void *user_data)
 static guint bt_uuid_hash(gconstpointer key)
 {
        const bt_uuid_t *uuid = key;
-       bt_uuid_t uuid_128;
-       uint64_t *val;
+       uint64_t uuid_128[2];
 
        if (!uuid)
                return 0;
 
-       bt_uuid_to_uuid128(uuid, &uuid_128);
-       val = (uint64_t *)&uuid_128.value.u128;
+       bt_uuid_to_uuid128(uuid, (bt_uuid_t *)uuid_128);
 
-       return g_int64_hash(val) ^ g_int64_hash(val+1);
+       return g_int64_hash(uuid_128) ^ g_int64_hash(uuid_128+1);
 }
 
 static gboolean bt_uuid_equal(gconstpointer v1, gconstpointer v2)