lib/cmdline: Fix an invalid format specifier in an assertion msg
authorDavid Gow <davidgow@google.com>
Wed, 21 Feb 2024 09:27:15 +0000 (17:27 +0800)
committerShuah Khan <skhan@linuxfoundation.org>
Tue, 27 Feb 2024 22:25:56 +0000 (15:25 -0700)
The correct format specifier for p - n (both p and n are pointers) is
%td, as the type should be ptrdiff_t.

This was discovered by annotating KUnit assertion macros with gcc's
printf specifier, but note that gcc incorrectly suggested a %d or %ld
specifier (depending on the pointer size of the architecture being
built).

Fixes: 0ea09083116d ("lib/cmdline: Allow get_options() to take 0 to validate the input")
Signed-off-by: David Gow <davidgow@google.com>
Tested-by: Guenter Roeck <linux@roeck-us.net>
Reviewed-by: Daniel Latypov <dlatypov@google.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
lib/cmdline_kunit.c

index d4572dbc914539a56c8b2a6da5ab101a9e11d80d..705b82736be0890de9417ca62233479eb3999cd9 100644 (file)
@@ -124,7 +124,7 @@ static void cmdline_do_one_range_test(struct kunit *test, const char *in,
                            n, e[0], r[0]);
 
        p = memchr_inv(&r[1], 0, sizeof(r) - sizeof(r[0]));
-       KUNIT_EXPECT_PTR_EQ_MSG(test, p, NULL, "in test %u at %u out of bound", n, p - r);
+       KUNIT_EXPECT_PTR_EQ_MSG(test, p, NULL, "in test %u at %td out of bound", n, p - r);
 }
 
 static void cmdline_test_range(struct kunit *test)