diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2010-03-30 15:28:36 +0200 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2010-03-30 15:30:14 +0200 |
commit | ceb072da340633cd655dc343f416b4a37343245e (patch) | |
tree | d880643c3de69fbdbeed92ee4bd7ce002a5a8b49 /openbsc/src/db.c | |
parent | b6e1a40c9c3e9ac1bade68b4b3c9e3c4665f79dc (diff) |
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
Diffstat (limited to 'openbsc/src/db.c')
-rw-r--r-- | openbsc/src/db.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/openbsc/src/db.c b/openbsc/src/db.c index 312d0f233..8bf47ab38 100644 --- a/openbsc/src/db.c +++ b/openbsc/src/db.c @@ -288,6 +288,8 @@ struct gsm_subscriber *db_create_subscriber(struct gsm_network *net, char *imsi) 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 @@ static int get_equipment_by_subscr(struct gsm_subscriber *subscr) 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"); |