[PATCH] libosmocore[master]: gsm23003_test: fix: compare members instead of bcmp

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/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Thu Mar 1 18:34:42 UTC 2018


Review at  https://gerrit.osmocom.org/7032

gsm23003_test: fix: compare members instead of bcmp

In certain builds (for me a build with no -O2 flag) the recently added
gsm23003_test test_mnc_from_str() fails, because bcmp() compares all bytes of
sizeof(struct test_mnc_from_str_result), which has valid data for 7 bytes plus
one padding byte that may contain arbitrary values. Instead of bcmp(), rather
compare the actual members one by one.

Change-Id: I28b28457c7b0462c950612fd9b87b5c7181d8bad
---
M tests/gsm23003/gsm23003_test.c
1 file changed, 3 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/32/7032/1

diff --git a/tests/gsm23003/gsm23003_test.c b/tests/gsm23003/gsm23003_test.c
index 4411e29..ea08d0d 100644
--- a/tests/gsm23003/gsm23003_test.c
+++ b/tests/gsm23003/gsm23003_test.c
@@ -159,7 +159,9 @@
 
 		result.rc = osmo_mnc_from_str(t->mnc_str, &result.mnc,
 						     &result.mnc_3_digits);
-		ok = !bcmp(&result, &t->expect, sizeof(result));
+		ok = (result.rc == t->expect.rc)
+		     && (result.mnc == t->expect.mnc)
+		     && (result.mnc_3_digits == t->expect.mnc_3_digits);
 		printf("%2d: \"%s\" rc=%d mnc=%u mnc_3_digits=%u %s\n",
 		       i, osmo_escape_str(t->mnc_str, -1), result.rc, result.mnc, result.mnc_3_digits,
 		       ok ? "pass" : "FAIL");

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I28b28457c7b0462c950612fd9b87b5c7181d8bad
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list