summaryrefslogtreecommitdiff
path: root/tests/lib/b64_decode-test.c
diff options
context:
space:
mode:
authorNico Huber <nico.h@gmx.de>2024-08-25 19:41:24 +0200
committerNico Huber <nico.h@gmx.de>2024-08-26 18:49:54 +0000
commitb8a1115f516874156814ffb6f8c2ccf86bce5ae2 (patch)
tree9c0d3447cbd5af1ddc2bc8670de16533ba69922f /tests/lib/b64_decode-test.c
parent4b0fe8c8cd2a26c2ae043b1b0753497a53aa000c (diff)
b64_decode-test: Properly terminate strings before comparison
Undefined behavior in unit-tests is no fun. assert_string_equal() expects properly zero-terminated strings. None of the encoded test strings contain a termination, hence add it manually. Without this change, the test was often failing with a wrong error message: [==========] tests_lib_b64_decode-test(tests): Running 1 test(s). [ RUN ] test_b64_decode [ ERROR ] --- "AB" != "AB" [ LINE ] --- tests/lib/b64_decode-test.c:38: error: Failure! [ FAILED ] test_b64_decode [==========] tests_lib_b64_decode-test(tests): 1 test(s) run. Probably due to unprintable characters in the string. No idea why my system is more susceptible to this issue. Change-Id: Id1bd2c3ff06bc1d4e5aa21ddd0f1d5802540999d Signed-off-by: Nico Huber <nico.h@gmx.de> Reviewed-on: https://review.coreboot.org/c/coreboot/+/84088 Reviewed-by: Jakub Czapiga <czapiga@google.com> Reviewed-by: Nicholas Sudsgaard <devel+coreboot@nsudsgaard.com> Reviewed-by: Paul Menzel <paulepanter@mailbox.org> Reviewed-by: Matt DeVillier <matt.devillier@gmail.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'tests/lib/b64_decode-test.c')
-rw-r--r--tests/lib/b64_decode-test.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/tests/lib/b64_decode-test.c b/tests/lib/b64_decode-test.c
index 189ce96237..8560eb2ccc 100644
--- a/tests/lib/b64_decode-test.c
+++ b/tests/lib/b64_decode-test.c
@@ -35,6 +35,9 @@ static void test_b64_decode(void **state)
res = b64_decode((uint8_t *)messages[i].enc, strlen(messages[i].enc), decoded);
assert_int_equal(res, (strlen(messages[i].dec)));
+
+ decoded[res] = 0x00;
+
assert_string_equal((const char *)decoded, messages[i].dec);
free(decoded);