kunit: Assign strings to 'const char*' in STREQ assertions

Currently, the KUNIT_EXPECT_STREQ() and related macros assign both
string arguments to variables of their own type (via typeof()). This
seems to be to prevent the macro argument from being evaluated multiple
times.

However, this doesn't work if one of these is a fixed-length character
array, rather than a character pointer, as (for example) char[16] will
always allocate a new string.

By always using 'const char*' (the type strcmp expects), we're always
just taking a pointer to the string, which works even with character
arrays.

Signed-off-by: David Gow <davidgow@google.com>
Reviewed-by: Daniel Latypov <dlatypov@google.com>
Reviewed-by: Brendan Higgins <brendanhiggins@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
This commit is contained in:
David Gow 2021-05-13 12:31:56 -07:00 committed by Shuah Khan
parent 6e62dfa6d1
commit 3747b5c0d8

View File

@ -1128,8 +1128,8 @@ do { \
fmt, \
...) \
do { \
typeof(left) __left = (left); \
typeof(right) __right = (right); \
const char *__left = (left); \
const char *__right = (right); \
\
KUNIT_ASSERTION(test, \
strcmp(__left, __right) op 0, \