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

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

pespin gerrit-no-reply at lists.osmocom.org
Mon Jul 29 14:56:13 UTC 2019


pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/14979


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(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/79/14979/1

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);
 
 	msgb_free(msg);
 }

-- 
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/14979
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I17fe7a0a5dc650f050bba1f47d071be749550729
Gerrit-Change-Number: 14979
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190729/3d407085/attachment.htm>


More information about the gerrit-log mailing list