Skip to content

Commit 04cb668

Browse files
committed
print_error_report: Paying extra caution on address alignment.
1 parent cfae2e3 commit 04cb668

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

platform/source/mbed_error.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,9 +578,11 @@ static void print_error_report(const mbed_error_ctx *ctx, const char *error_msg,
578578

579579
#if MBED_STACK_DUMP_ENABLED && defined(MBED_CONF_RTOS_PRESENT)
580580
#define STACK_DUMP_WIDTH 8
581+
#define INT_ALIGN_MASK (~(sizeof(int) - 1))
581582
mbed_error_printf("\n\nStack Dump:");
582-
uint32_t st_end = ctx->thread_stack_mem + ctx->thread_stack_size;
583-
for (uint32_t st = ctx->thread_current_sp; st <= st_end; st += sizeof(int) * STACK_DUMP_WIDTH) {
583+
uint32_t st_end = (ctx->thread_stack_mem + ctx->thread_stack_size) & INT_ALIGN_MASK;
584+
uint32_t st = (ctx->thread_current_sp) & INT_ALIGN_MASK;
585+
for (; st <= st_end; st += sizeof(int) * STACK_DUMP_WIDTH) {
584586
mbed_error_printf("\n0x%08" PRIX32 ":", st);
585587
for (int i = 0; i < STACK_DUMP_WIDTH; i++) {
586588
uint32_t st_cur = st + i * sizeof(int);

0 commit comments

Comments
 (0)