diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2019-07-29 16:44:22 +0200 |
---|---|---|
committer | pespin <pespin@sysmocom.de> | 2019-07-30 12:51:29 +0000 |
commit | 2605ffc3d70a7cf0be5828cc565d4d270a317a81 (patch) | |
tree | c90faf78a1eae24689f40fa12d425807d894c7f8 | |
parent | 5c4b9850c21009f20042b1e3920e602f6f6df30f (diff) |
gsm0808_test: Fix wrong use of memcp
After recent system upgrade, gcc 9.1.0, I started getting gsm0808_test
failing locally:
Assert failed memcmp(&enc_ct, &dec_ct, sizeof(enc_ct)) == 0 libosmocore/tests/gsm0808/gsm0808_test.c:992
During investigation with gdb, fields of both structures seem to contain
same values. However, closer lookup gives some hints on why it fails:
(gdb) print memcmp(&enc_ct, &dec_ct, sizeof(enc_ct))
$1 = 85
(gdb) print memcmp(&enc_ct, &dec_ct, 12)
$14 = 85
(gdb) print ((uint8_t*)&enc_ct)[11]
$15 = 85 'U'
(gdb) print ((uint8_t*)&dec_ct)[11]
$16 = 0 '\000'
So the 12th byte in struct gsm0808_channel_type is basically an
alignment padding byte added by the compiler (to align perm_spch_len to
4-byte alignment). Since both compared structs are initialized without
memset(0) but using compiler's designated initializers, it seems the compiler
decided it's no longer needed to zero the padding byte, making memcp fail in
this case.
In order to avoid the failure, let's properly check every field instead
of using memcp here.
Change-Id: I17fe7a0a5dc650f050bba1f47d071be749550729
-rw-r--r-- | tests/gsm0808/gsm0808_test.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/tests/gsm0808/gsm0808_test.c b/tests/gsm0808/gsm0808_test.c index 8f1e2993..2389218a 100644 --- a/tests/gsm0808/gsm0808_test.c +++ b/tests/gsm0808/gsm0808_test.c @@ -989,7 +989,10 @@ static void test_gsm0808_enc_dec_channel_type() rc_dec = gsm0808_dec_channel_type(&dec_ct, msg->data + 2, msg->len - 2); OSMO_ASSERT(rc_dec == 4); - OSMO_ASSERT(memcmp(&enc_ct, &dec_ct, sizeof(enc_ct)) == 0); + OSMO_ASSERT(enc_ct.ch_indctr == dec_ct.ch_indctr); + OSMO_ASSERT(enc_ct.ch_rate_type == dec_ct.ch_rate_type); + OSMO_ASSERT(enc_ct.perm_spch_len == dec_ct.perm_spch_len); + OSMO_ASSERT(memcmp(&enc_ct.perm_spch[0], &dec_ct.perm_spch[0], enc_ct.perm_spch_len) == 0); msgb_free(msg); } |