aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2017-11-18 18:29:49 +0100
committerNeels Hofmeyr <nhofmeyr@sysmocom.de>2017-11-29 16:20:57 +0000
commit1d85bea152506b4c812eafaccb0d390678f17ca9 (patch)
tree1beda88f799d7ba7a0b16b494392ee12d60bbcf2
parentf1e44c5493eec4f43006747e98ed8bddbf468c4c (diff)
sanitize build: ensure uint16/32 alignment in gtpie_test and in46a_test
Fixes sanitize build failures: Testing gtpie_tlv() ../../../../src/osmo-ggsn/tests/gtp/gtpie_test.c:30:2: runtime error: load of misaligned address 0x55c0a0830f21 for type 'uint16_t', which requires 2 byte alignment 0x55c0a0830f21: note: pointer points here 00 00 00 17 00 06 01 02 03 04 05 06 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ Testing gtpie_tv0() Testing gtpie_tv1() Testing gtpie_tv2() ../../../../src/osmo-ggsn/tests/gtp/gtpie_test.c:76:2: runtime error: load of misaligned address 0x55c0a0830f21 for type 'uint16_t', which requires 2 byte alignment 0x55c0a0830f21: note: pointer points here 00 00 00 2a ab cd 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ Testing gtpie_tv4() ../../../../src/osmo-ggsn/tests/gtp/gtpie_test.c:90:2: runtime error: load of misaligned address 0x55c0a0830f21 for type 'uint32_t', which requires 4 byte alignment 0x55c0a0830f21: note: pointer points here 00 00 00 2a ab cd 01 23 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ Testing gtpie_tv8() ../../../../src/osmo-ggsn/tests/gtp/gtpie_test.c:104:2: runtime error: load of misaligned address 0x55c0a0830f21 for type 'uint32_t', which requires 4 byte alignment 0x55c0a0830f21: note: pointer points here 00 00 00 2a 00 01 02 03 04 05 06 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ ../../../../src/osmo-ggsn/tests/gtp/gtpie_test.c:105:2: runtime error: load of misaligned address 0x55c0a0830f25 for type 'uint32_t', which requires 4 byte alignment 0x55c0a0830f25: note: pointer points here 00 01 02 03 04 05 06 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ^ Change-Id: I9eb16450af942d6464211e190f6a4d5a1d814842
-rw-r--r--tests/gtp/gtpie_test.c11
-rw-r--r--tests/lib/in46a_test.c3
2 files changed, 8 insertions, 6 deletions
diff --git a/tests/gtp/gtpie_test.c b/tests/gtp/gtpie_test.c
index 8d87dcc..e3bc2e0 100644
--- a/tests/gtp/gtpie_test.c
+++ b/tests/gtp/gtpie_test.c
@@ -7,6 +7,7 @@
#include <osmocom/core/utils.h>
#include <osmocom/core/application.h>
#include <osmocom/core/logging.h>
+#include <osmocom/core/bits.h>
#include "../../lib/syserr.h"
#include "../../gtp/gtpie.h"
@@ -27,7 +28,7 @@ static void test_gtpie_tlv()
OSMO_ASSERT(rc == 0);
OSMO_ASSERT(len == sizeof(in) + 3);
OSMO_ASSERT(buf[0] == 23);
- OSMO_ASSERT(ntohs(*(uint16_t *) &buf[1]) == sizeof(in));
+ OSMO_ASSERT(osmo_load16be(&buf[1]) == sizeof(in));
OSMO_ASSERT(!memcmp(buf+3, in, sizeof(in)));
/* overflow */
@@ -73,7 +74,7 @@ static void test_gtpie_tv2()
OSMO_ASSERT(rc == 0);
OSMO_ASSERT(len == 3);
OSMO_ASSERT(buf[0] == 42);
- OSMO_ASSERT(ntohs(*(uint16_t *) &buf[1]) == 0xABCD);
+ OSMO_ASSERT(osmo_load16be(&buf[1]) == 0xABCD);
}
static void test_gtpie_tv4()
@@ -87,7 +88,7 @@ static void test_gtpie_tv4()
OSMO_ASSERT(rc == 0);
OSMO_ASSERT(len == 5);
OSMO_ASSERT(buf[0] == 42);
- OSMO_ASSERT(ntohl(*(uint32_t *) &buf[1]) == 0xABCD0123);
+ OSMO_ASSERT(osmo_load32be(&buf[1]) == 0xABCD0123);
}
static void test_gtpie_tv8()
@@ -101,8 +102,8 @@ static void test_gtpie_tv8()
OSMO_ASSERT(rc == 0);
OSMO_ASSERT(len == 9);
OSMO_ASSERT(buf[0] == 42);
- OSMO_ASSERT(ntohl(*(uint32_t *) &buf[1]) == 0x00010203);
- OSMO_ASSERT(ntohl(*(uint32_t *) &buf[5]) == 0x04050607);
+ OSMO_ASSERT(osmo_load32be(&buf[1]) == 0x00010203);
+ OSMO_ASSERT(osmo_load32be(&buf[5]) == 0x04050607);
}
int main(int argc, char **argv)
diff --git a/tests/lib/in46a_test.c b/tests/lib/in46a_test.c
index ab7156f..d4a5dbc 100644
--- a/tests/lib/in46a_test.c
+++ b/tests/lib/in46a_test.c
@@ -10,6 +10,7 @@
#include <osmocom/core/utils.h>
#include <osmocom/core/application.h>
#include <osmocom/core/logging.h>
+#include <osmocom/core/bits.h>
#include "../../lib/in46_addr.h"
#include "../../lib/syserr.h"
@@ -171,7 +172,7 @@ static void test_in46a_to_eua(void)
OSMO_ASSERT(in46a_to_eua(&g_ia4, &eua) == 0);
OSMO_ASSERT(eua.v[0] == PDP_EUA_ORG_IETF);
OSMO_ASSERT(eua.v[1] == PDP_EUA_TYPE_v4);
- OSMO_ASSERT(*(uint32_t *) &eua.v[2] == g_ia4.v4.s_addr);
+ OSMO_ASSERT(osmo_load32le(&eua.v[2]) == g_ia4.v4.s_addr);
/* IPv6 address */
OSMO_ASSERT(in46a_to_eua(&g_ia6, &eua) == 0);