db: Fix aliasing warning by casting the signed char to a struct
When we have assigned the cn we will use mempcy to copy the one
byte into the target. Use a static assert to assure that the type
have the same size.
warning: dereferencing type-punned pointer will break strict-aliasing rules
diff --git a/openbsc/src/db.c b/openbsc/src/db.c
index 312d0f2..8bf47ab 100644
--- a/openbsc/src/db.c
+++ b/openbsc/src/db.c
@@ -288,6 +288,8 @@
return subscr;
}
+static_assert(sizeof(unsigned char) == sizeof(struct gsm48_classmark1), classmark1_size);
+
static int get_equipment_by_subscr(struct gsm_subscriber *subscr)
{
dbi_result result;
@@ -316,9 +318,10 @@
strncpy(equip->imei, string, sizeof(equip->imei));
string = dbi_result_get_string(result, "classmark1");
- if (string)
- cm1 = atoi(string) & 0xff;
- equip->classmark1 = *((struct gsm48_classmark1 *) &cm1);
+ if (string) {
+ cm1 = atoi(string) & 0xff;
+ memcpy(&equip->classmark1, &cm1, sizeof(equip->classmark1));
+ }
equip->classmark2_len = dbi_result_get_field_length(result, "classmark2");
cm2 = dbi_result_get_binary(result, "classmark2");