Skip to content

Commit 0a549ed

Browse files
sulixshuahkh
authored andcommitted
lib: memcpy_kunit: Fix an invalid format specifier in an assertion msg
The 'i' passed as an assertion message is a size_t, so should use '%zu', not '%d'. This was found by annotating the _MSG() variants of KUnit's assertions to let gcc validate the format strings. Fixes: bb95ebb ("lib: Introduce CONFIG_MEMCPY_KUNIT_TEST") Signed-off-by: David Gow <davidgow@google.com> Tested-by: Guenter Roeck <linux@roeck-us.net> Reviewed-by: Justin Stitt <justinstitt@google.com> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
1 parent d2733a0 commit 0a549ed

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/memcpy_kunit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct some_bytes {
3232
BUILD_BUG_ON(sizeof(instance.data) != 32); \
3333
for (size_t i = 0; i < sizeof(instance.data); i++) { \
3434
KUNIT_ASSERT_EQ_MSG(test, instance.data[i], v, \
35-
"line %d: '%s' not initialized to 0x%02x @ %d (saw 0x%02x)\n", \
35+
"line %d: '%s' not initialized to 0x%02x @ %zu (saw 0x%02x)\n", \
3636
__LINE__, #instance, v, i, instance.data[i]); \
3737
} \
3838
} while (0)
@@ -41,7 +41,7 @@ struct some_bytes {
4141
BUILD_BUG_ON(sizeof(one) != sizeof(two)); \
4242
for (size_t i = 0; i < sizeof(one); i++) { \
4343
KUNIT_EXPECT_EQ_MSG(test, one.data[i], two.data[i], \
44-
"line %d: %s.data[%d] (0x%02x) != %s.data[%d] (0x%02x)\n", \
44+
"line %d: %s.data[%zu] (0x%02x) != %s.data[%zu] (0x%02x)\n", \
4545
__LINE__, #one, i, one.data[i], #two, i, two.data[i]); \
4646
} \
4747
kunit_info(test, "ok: " TEST_OP "() " name "\n"); \

0 commit comments

Comments
 (0)