Skip to content

Commit 9b66093

Browse files
ldv-altgregkh
authored andcommitted
selftests: harness: fix printing of mismatch values in __EXPECT()
[ Upstream commit 02bc220 ] intptr_t and uintptr_t are not big enough types on 32-bit architectures when printing 64-bit values, resulting to the following incorrect diagnostic output: # get_syscall_info.c:209:get_syscall_info:Expected exp_args[2] (3134324433) == info.entry.args[1] (3134324433) Replace intptr_t and uintptr_t with intmax_t and uintmax_t, respectively. With this fix, the same test produces more usable diagnostic output: # get_syscall_info.c:209:get_syscall_info:Expected exp_args[2] (3134324433) == info.entry.args[1] (18446744072548908753) Link: https://lore.kernel.org/r/20250108170757.GA6723@strace.io Fixes: b5bb6d3 ("selftests/seccomp: fix 32-bit build warnings") Signed-off-by: Dmitry V. Levin <ldv@strace.io> Reviewed-by: Kees Cook <kees@kernel.org> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent f42247a commit 9b66093

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

tools/testing/selftests/kselftest_harness.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -760,33 +760,33 @@
760760
/* Report with actual signedness to avoid weird output. */ \
761761
switch (is_signed_type(__exp) * 2 + is_signed_type(__seen)) { \
762762
case 0: { \
763-
unsigned long long __exp_print = (uintptr_t)__exp; \
764-
unsigned long long __seen_print = (uintptr_t)__seen; \
765-
__TH_LOG("Expected %s (%llu) %s %s (%llu)", \
763+
uintmax_t __exp_print = (uintmax_t)__exp; \
764+
uintmax_t __seen_print = (uintmax_t)__seen; \
765+
__TH_LOG("Expected %s (%ju) %s %s (%ju)", \
766766
_expected_str, __exp_print, #_t, \
767767
_seen_str, __seen_print); \
768768
break; \
769769
} \
770770
case 1: { \
771-
unsigned long long __exp_print = (uintptr_t)__exp; \
772-
long long __seen_print = (intptr_t)__seen; \
773-
__TH_LOG("Expected %s (%llu) %s %s (%lld)", \
771+
uintmax_t __exp_print = (uintmax_t)__exp; \
772+
intmax_t __seen_print = (intmax_t)__seen; \
773+
__TH_LOG("Expected %s (%ju) %s %s (%jd)", \
774774
_expected_str, __exp_print, #_t, \
775775
_seen_str, __seen_print); \
776776
break; \
777777
} \
778778
case 2: { \
779-
long long __exp_print = (intptr_t)__exp; \
780-
unsigned long long __seen_print = (uintptr_t)__seen; \
781-
__TH_LOG("Expected %s (%lld) %s %s (%llu)", \
779+
intmax_t __exp_print = (intmax_t)__exp; \
780+
uintmax_t __seen_print = (uintmax_t)__seen; \
781+
__TH_LOG("Expected %s (%jd) %s %s (%ju)", \
782782
_expected_str, __exp_print, #_t, \
783783
_seen_str, __seen_print); \
784784
break; \
785785
} \
786786
case 3: { \
787-
long long __exp_print = (intptr_t)__exp; \
788-
long long __seen_print = (intptr_t)__seen; \
789-
__TH_LOG("Expected %s (%lld) %s %s (%lld)", \
787+
intmax_t __exp_print = (intmax_t)__exp; \
788+
intmax_t __seen_print = (intmax_t)__seen; \
789+
__TH_LOG("Expected %s (%jd) %s %s (%jd)", \
790790
_expected_str, __exp_print, #_t, \
791791
_seen_str, __seen_print); \
792792
break; \

0 commit comments

Comments
 (0)