Skip to content

Commit 7b1ea16

Browse files
Damian-Nordicrlubos
authored andcommitted
nrf_rpc: rpc_utils: fix stack overflow trigger
Write to the stack array to prevent the compiler from optimizing it away. Signed-off-by: Damian Krolik <[email protected]>
1 parent 50efc9a commit 7b1ea16

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

subsys/nrf_rpc/rpc_utils/server/crash_gen.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ K_WORK_DELAYABLE_DEFINE(crash_work, crash_work_handler);
1515

1616
static void do_stack_overflow(void)
1717
{
18-
volatile uint8_t arr[(256 * 1024)] __attribute__((unused));
18+
volatile uint8_t arr[CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE];
19+
20+
/* Write to 'arr' to prevent the compiler from optimizing it away. */
21+
arr[0] = 1;
1922
}
2023

2124
static void do_assert(void)
@@ -28,7 +31,9 @@ static void do_assert(void)
2831

2932
static void do_hardfault(void)
3033
{
31-
volatile uint32_t value __attribute__((unused)) = 1 / 0;
34+
volatile uint32_t value;
35+
36+
value = 1 / 0;
3237
}
3338

3439
#pragma GCC diagnostic pop

0 commit comments

Comments
 (0)