Skip to content

Commit 10299c0

Browse files
committed
kunit/fortify: Add back "volatile" for sizeof() constants
It seems the Clang can see through OPTIMIZER_HIDE_VAR when the constant is coming from sizeof. Adding "volatile" back to these variables solves this false positive without reintroducing the issues that originally led to switching to OPTIMIZER_HIDE_VAR in the first place[1]. Reported-by: Nathan Chancellor <[email protected]> Closes: ClangBuiltLinux/linux#2075 [1] Cc: Jannik Glückert <[email protected]> Suggested-by: Nathan Chancellor <[email protected]> Fixes: 6ee149f ("kunit/fortify: Replace "volatile" with OPTIMIZER_HIDE_VAR()") Reviewed-by: Nathan Chancellor <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent 5e54510 commit 10299c0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/tests/fortify_kunit.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,8 +1003,8 @@ static void fortify_test_memcmp(struct kunit *test)
10031003
{
10041004
char one[] = "My mind is going ...";
10051005
char two[] = "My mind is going ... I can feel it.";
1006-
size_t one_len = sizeof(one) - 1;
1007-
size_t two_len = sizeof(two) - 1;
1006+
volatile size_t one_len = sizeof(one) - 1;
1007+
volatile size_t two_len = sizeof(two) - 1;
10081008

10091009
OPTIMIZER_HIDE_VAR(one_len);
10101010
OPTIMIZER_HIDE_VAR(two_len);

0 commit comments

Comments
 (0)