From: Frantisek Sumsal Date: Mon, 8 Apr 2024 18:32:10 +0000 (+0200) Subject: test: handle NULL correctly when passed to ASSERT_EQ() X-Git-Tag: v256-rc1~243^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d7a3d47871b0be4864363e5064e98360cba5e2b;p=thirdparty%2Fsystemd.git test: handle NULL correctly when passed to ASSERT_EQ() strcmp() doesn't handle NULLs nicely, so switch to streq_ptr(). --- diff --git a/src/shared/tests.h b/src/shared/tests.h index 85f9463f9b5..a8fa4a6622e 100644 --- a/src/shared/tests.h +++ b/src/shared/tests.h @@ -249,11 +249,10 @@ static inline int run_test_table(void) { #define ASSERT_STREQ(expr1, expr2) \ ({ \ - const char* _expr1 = (expr1); \ - const char* _expr2 = (expr2); \ - if (strcmp(_expr1, _expr2) != 0) { \ + const char *_expr1 = (expr1), *_expr2 = (expr2); \ + if (!streq_ptr(_expr1, _expr2)) { \ log_error("%s:%i: Assertion failed: expected \"%s == %s\", but \"%s != %s\"", \ - PROJECT_FILE, __LINE__, #expr1, #expr2, _expr1, _expr2); \ + PROJECT_FILE, __LINE__, #expr1, #expr2, strnull(_expr1), strnull(_expr2)); \ abort(); \ } \ })