diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2017-11-18 21:00:41 +0100 |
---|---|---|
committer | Neels Hofmeyr <neels@hofmeyr.de> | 2017-11-22 03:11:40 +0100 |
commit | 54df0a1095f13b97638d39c81b5e165c44f3d949 (patch) | |
tree | 78e7a8644729cfe8cf8f0635ec777e1a13926e46 | |
parent | d9cb19a8fbb3b6f7b29617fa78fd8bf7492a6667 (diff) |
ranap_msg_factory: sanitize: memcpy instead of unaligned int copy
The sanitize build complains about writing to a uint32_t that is not 4-byte
aligned. Instead, write the uint32_t by memcpy.
For that, move the common ntohl() to the top and store in a local uint32_t,
memcpy() from that in both code paths.
Change-Id: Iacdd15421f824dd009448a96355b533dff28258b
-rw-r--r-- | src/ranap_msg_factory.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/ranap_msg_factory.c b/src/ranap_msg_factory.c index ef3e9ef..fe7e325 100644 --- a/src/ranap_msg_factory.c +++ b/src/ranap_msg_factory.c @@ -638,6 +638,7 @@ static void new_transp_layer_addr(BIT_STRING_t *out, uint32_t ip, bool use_x213_ { uint8_t *buf; unsigned int len; + uint32_t ip_h = ntohl(ip); if (use_x213_nsap) { len = 160/8; @@ -645,11 +646,11 @@ static void new_transp_layer_addr(BIT_STRING_t *out, uint32_t ip, bool use_x213_ buf[0] = 0x35; /* AFI For IANA ICP */ buf[1] = 0x00; /* See A.5.2.1.2.7 of X.213 */ buf[2] = 0x01; - *(uint32_t *)&buf[3] = ntohl(ip); + memcpy(&buf[3], &ip_h, sizeof(ip_h)); } else { - len = 4; + len = sizeof(ip_h); buf = CALLOC(len, sizeof(uint8_t)); - *(uint32_t *)buf = ntohl(ip); + memcpy(buf, &ip_h, sizeof(ip_h)); } out->buf = buf; out->size = len; |