From 444d7d8e65447ca871db00828d2eda1490c2bbe7 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Fri, 4 Apr 2014 13:01:28 +0200 Subject: ipa: Fix compiler warnings about aliasing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use memcpy to copy from the OML message into the stack and then convert the network byte order. network_listen.c: In function ‘test_rep’: network_listen.c:145:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] test_rep_len = ntohs(*(uint16_t *) &foh->data[3]); ^ network_listen.c:153:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] ferr_list_len = ntohs(*(uint16_t *) &foh->data[7]); ^ network_listen.c:164:3: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] ferr_list_len = ntohs(*(uint16_t *) &foh->data[7]); ^ network_listen.c:130:11: warning: variable ‘test_rep_len’ set but not used [-Wunused-but-set-variable] uint16_t test_rep_len, ferr_list_len; --- openbsc/src/ipaccess/network_listen.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'openbsc/src/ipaccess') diff --git a/openbsc/src/ipaccess/network_listen.c b/openbsc/src/ipaccess/network_listen.c index 6749c4aa3..3b44ceb74 100644 --- a/openbsc/src/ipaccess/network_listen.c +++ b/openbsc/src/ipaccess/network_listen.c @@ -142,7 +142,8 @@ static int test_rep(void *_msg) DEBUGPC(DNM, "test_no=0x%02x ", foh->data[1]); /* data[2] == NM_ATT_TEST_REPORT */ /* data[3..4]: test_rep_len */ - test_rep_len = ntohs(*(uint16_t *) &foh->data[3]); + memcpy(&test_rep_len, &foh->data[3], sizeof(uint16_t)); + test_rep_len = ntohs(test_rep_len); /* data[5]: ip.access test result */ DEBUGPC(DNM, "tst_res=%s\n", ipacc_testres_name(foh->data[5])); @@ -150,7 +151,8 @@ static int test_rep(void *_msg) switch (foh->data[6]) { case NM_IPAC_EIE_FREQ_ERR_LIST: /* data[7..8]: length of ferr_list */ - ferr_list_len = ntohs(*(uint16_t *) &foh->data[7]); + memcpy(&ferr_list_len, &foh->data[7], sizeof(uint16_t)); + ferr_list_len = ntohs(ferr_list_len); /* data[9...]: frequency error list elements */ for (i = 0; i < ferr_list_len; i+= sizeof(*ife)) { @@ -161,7 +163,8 @@ static int test_rep(void *_msg) break; case NM_IPAC_EIE_CHAN_USE_LIST: /* data[7..8]: length of ferr_list */ - ferr_list_len = ntohs(*(uint16_t *) &foh->data[7]); + memcpy(&ferr_list_len, &foh->data[7], sizeof(uint16_t)); + ferr_list_len = ntohs(ferr_list_len); /* data[9...]: channel usage list elements */ for (i = 0; i < ferr_list_len; i+= 2) { -- cgit v1.2.3