From d80949d66d00e2da5009932cb18288df046462b1 Mon Sep 17 00:00:00 2001 From: Yunhee Seo Date: Mon, 22 Jul 2024 16:51:53 +0900 Subject: [PATCH] tests: Remove MATCH macro and change it to strncmp MATCH macro was used to compare two strings in wrong way. This because when the two string are compared by strncmp, the comparison length should be strlen + 1 of one string to avoid null string comparison case. Thus, MATCH macro is replaced by original strncmp function. Furthermore, using sizeof literal is more clear in terms of readability and maintenance. Change-Id: I00272ccb12f9424177bdab3a3d33a1f97617b29c Signed-off-by: Yunhee Seo --- tests/libcommon/test-common.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/libcommon/test-common.c b/tests/libcommon/test-common.c index 9f97bd2..e579dc5 100644 --- a/tests/libcommon/test-common.c +++ b/tests/libcommon/test-common.c @@ -167,17 +167,17 @@ static int test_parser(struct parse_result *result, void *data) { assert_int_equal(data, check_user_data); - if (MATCH(result->section, "Section1") && - MATCH(result->name, "Key1") && - MATCH(result->value, "Value1")) + if (!strncmp(result->section, "Section1", sizeof("Section1")) && + !strncmp(result->name, "Key1", sizeof("Key1")) && + !strncmp(result->value, "Value1", sizeof("Value1"))) checked1 = true; - else if (MATCH(result->section, "Section2") && - MATCH(result->name, "Key2") && - MATCH(result->value, "Value2")) + else if (!strncmp(result->section, "Section2", sizeof("Section2")) && + !strncmp(result->name, "Key2", sizeof("Key2")) && + !strncmp(result->value, "Value2", sizeof("Value2"))) checked2 = true; - else if (MATCH(result->section, "Section2") && - MATCH(result->name, "Key3") && - MATCH(result->value, "Value3")) + else if (!strncmp(result->section, "Section2", sizeof("Section2")) && + !strncmp(result->name, "Key3", sizeof("Key3")) && + !strncmp(result->value, "Value3", sizeof("Value3"))) checked3 = true; else garbage = true; -- 2.34.1