Change in ...libosmocore[master]: gsm0808_test: Fix wrong use of memcp

pespin gerrit-no-reply at
Tue Jul 30 12:51:29 UTC 2019

pespin has submitted this change and it was merged. ( )

Change subject: gsm0808_test: Fix wrong use of memcp

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
M tests/gsm0808/gsm0808_test.c
1 file changed, 4 insertions(+), 1 deletion(-)

  laforge: Looks good to me, but someone else must approve
  Vadim Yanitskiy: Looks good to me, but someone else must approve
  pespin: Looks good to me, approved
  Jenkins Builder: Verified

diff --git a/tests/gsm0808/gsm0808_test.c b/tests/gsm0808/gsm0808_test.c
index 8f1e299..2389218 100644
--- a/tests/gsm0808/gsm0808_test.c
+++ b/tests/gsm0808/gsm0808_test.c
@@ -989,7 +989,10 @@
 	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);

To view, visit
To unsubscribe, or for help writing mail filters, visit

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I17fe7a0a5dc650f050bba1f47d071be749550729
Gerrit-Change-Number: 14979
Gerrit-PatchSet: 2
Gerrit-Owner: pespin <pespin at>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy <axilirator at>
Gerrit-Reviewer: laforge <laforge at>
Gerrit-Reviewer: pespin <pespin at>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the gerrit-log mailing list