Skip to content

Commit cfbaac6

Browse files
committed
tests: kernel: Fix address-of-packed-mem warning
The warning below appears once -Waddress-of-packed-mem is enabled: /__w/zephyr/zephyr/tests/kernel/mem_protect/userspace/src/main.c: In function 'test_main': /__w/zephyr/zephyr/tests/kernel/mem_protect/userspace/src/main.c:1024:17: error: converting a packed 'k_thread_stack_t' {aka 'struct z_thread_stack_element'} pointer (alignment 1) to a 'struct z_x86_thread_stack_header' pointer (alignment 4096) may result in an unaligned pointer value [-Werror=address-of-packed-member] 1024 | hdr = ((struct z_x86_thread_stack_header *)ztest_thread_stack); To avoid the warning, use an intermediate void * variable. More info in #16587. Signed-off-by: Carles Cufi <[email protected]>
1 parent 710e03b commit cfbaac6

File tree

1 file changed

+4
-2
lines changed
  • tests/kernel/mem_protect/userspace/src

1 file changed

+4
-2
lines changed

tests/kernel/mem_protect/userspace/src/main.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,16 +1012,18 @@ void test_main(void)
10121012

10131013
#if defined(CONFIG_ARM64)
10141014
struct z_arm64_thread_stack_header *hdr;
1015+
void *vhdr = ((struct z_arm64_thread_stack_header *)ztest_thread_stack);
10151016

1016-
hdr = ((struct z_arm64_thread_stack_header *)ztest_thread_stack);
1017+
hdr = vhdr;
10171018
priv_stack_ptr = (((char *)&hdr->privilege_stack) +
10181019
(sizeof(hdr->privilege_stack) - 1));
10191020
#elif defined(CONFIG_ARM)
10201021
priv_stack_ptr = (char *)z_priv_stack_find(ztest_thread_stack);
10211022
#elif defined(CONFIG_X86)
10221023
struct z_x86_thread_stack_header *hdr;
1024+
void *vhdr = ((struct z_x86_thread_stack_header *)ztest_thread_stack);
10231025

1024-
hdr = ((struct z_x86_thread_stack_header *)ztest_thread_stack);
1026+
hdr = vhdr;
10251027
priv_stack_ptr = (((char *)&hdr->privilege_stack) +
10261028
(sizeof(hdr->privilege_stack) - 1));
10271029
#elif defined(CONFIG_RISCV)

0 commit comments

Comments
 (0)