From 3ad37fbebc2341e895a7e35771c5261b5fc5ae79 Mon Sep 17 00:00:00 2001 From: Inaky Perez-Gonzalez Date: Thu, 27 Oct 2016 17:19:31 -0700 Subject: [PATCH] tc_util: protect macro arg expansion Calling TC_END_REPORT(complex_expression) might have side effects when complex_expression is later put inside (result == TC_PASS? A : B) evaluation, because result will be replaced verbatim. To avoid operator assignment order changing things, protect replacement of result by adding parenthesis. Change-Id: I8fd07d97d4b49b4cd48a1c6ad345bf49fb2537b5 Signed-off-by: Inaky Perez-Gonzalez --- tests/include/tc_util.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/include/tc_util.h b/tests/include/tc_util.h index a2517a893da..85a3e8fff16 100644 --- a/tests/include/tc_util.h +++ b/tests/include/tc_util.h @@ -80,14 +80,14 @@ #define TC_END(result, fmt, ...) PRINT_DATA(fmt, ##__VA_ARGS__) /* prints result and the function name */ -#define _TC_END_RESULT(result, func) \ - do { \ - PRINT_LINE; \ - TC_END(result, "%s - %s.\n", \ - result == TC_PASS ? PASS : FAIL, func); \ +#define _TC_END_RESULT(result, func) \ + do { \ + PRINT_LINE; \ + TC_END(result, "%s - %s.\n", \ + (result) == TC_PASS ? PASS : FAIL, func); \ } while (0) #define TC_END_RESULT(result) \ - _TC_END_RESULT(result, __func__) + _TC_END_RESULT((result), __func__) #define TC_END_REPORT(result) \ do { \ @@ -95,7 +95,7 @@ TC_PRINT_RUNID; \ TC_END(result, \ "PROJECT EXECUTION %s\n", \ - result == TC_PASS ? "SUCCESSFUL" : "FAILED"); \ + (result) == TC_PASS ? "SUCCESSFUL" : "FAILED"); \ } while (0) #endif /* __TC_UTIL_H__ */