Harald Welte has submitted this change and it was merged.

Change subject: sanitize build: ensure uint16/32 alignment in gtpie_test and 
in46a_test
......................................................................


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
---
M tests/gtp/gtpie_test.c
M tests/lib/in46a_test.c
2 files changed, 8 insertions(+), 6 deletions(-)

Approvals:
  Max: Looks good to me, but someone else must approve
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



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 @@
        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 @@
        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 @@
        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 @@
        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 @@
        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);

-- 
To view, visit https://gerrit.osmocom.org/4915
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9eb16450af942d6464211e190f6a4d5a1d814842
Gerrit-PatchSet: 7
Gerrit-Project: osmo-ggsn
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <[email protected]>
Gerrit-Reviewer: Harald Welte <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <[email protected]>
Gerrit-Reviewer: Neels Hofmeyr <[email protected]>

Reply via email to