Skip to content

Commit 638e071

Browse files
committed
mbed_error.c: Fix format specifiers
1 parent 82a9072 commit 638e071

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

platform/mbed_error.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
#if DEVICE_STDIO_MESSAGES
2929
#include <stdio.h>
3030
#endif
31+
#ifndef __STDC_FORMAT_MACROS
32+
#define __STDC_FORMAT_MACROS
33+
#endif
34+
#include <inttypes.h>
3135

3236
#ifndef NDEBUG
3337
#define ERROR_REPORT(ctx, error_msg, error_filename, error_line) print_error_report(ctx, error_msg, error_filename, error_line)
@@ -278,7 +282,7 @@ static const char *name_or_unnamed(const char *name)
278282
/* Prints info of a thread(using osRtxThread_t struct)*/
279283
static void print_thread(const osRtxThread_t *thread)
280284
{
281-
mbed_error_printf("\n%s State: 0x%X Entry: 0x%08X Stack Size: 0x%08X Mem: 0x%08X SP: 0x%08X", name_or_unnamed(thread->name), thread->state, thread->thread_addr, thread->stack_size, (uint32_t)thread->stack_mem, thread->sp);
285+
mbed_error_printf("\n%s State: 0x%" PRIX8 " Entry: 0x%08" PRIX32 " Stack Size: 0x%08" PRIX32 " Mem: 0x%08" PRIX32 " SP: 0x%08" PRIX32, name_or_unnamed(thread->name), thread->state, thread->thread_addr, thread->stack_size, (uint32_t)thread->stack_mem, thread->sp);
282286
}
283287

284288
/* Prints thread info from a list */
@@ -294,43 +298,43 @@ static void print_threads_info(const osRtxThread_t *threads)
294298
#ifndef NDEBUG
295299
static void print_error_report(const mbed_error_ctx *ctx, const char *error_msg, const char *error_filename, int error_line)
296300
{
297-
uint32_t error_code = MBED_GET_ERROR_CODE(ctx->error_status);
298-
uint32_t error_module = MBED_GET_ERROR_MODULE(ctx->error_status);
301+
int error_code = MBED_GET_ERROR_CODE(ctx->error_status);
302+
int error_module = MBED_GET_ERROR_MODULE(ctx->error_status);
299303

300304
mbed_error_printf("\n\n++ MbedOS Error Info ++\nError Status: 0x%X Code: %d Module: %d\nError Message: ", ctx->error_status, error_code, error_module);
301305

302306
switch (error_code) {
303307
//These are errors reported by kernel handled from mbed_rtx_handlers
304308
case MBED_ERROR_CODE_RTOS_EVENT:
305-
mbed_error_printf("Kernel Error: 0x%X, ", ctx->error_value);
309+
mbed_error_printf("Kernel Error: 0x%" PRIX32 ", ", ctx->error_value);
306310
break;
307311

308312
case MBED_ERROR_CODE_RTOS_THREAD_EVENT:
309-
mbed_error_printf("Thread: 0x%X, ", ctx->error_value);
313+
mbed_error_printf("Thread: 0x%" PRIX32 ", ", ctx->error_value);
310314
break;
311315

312316
case MBED_ERROR_CODE_RTOS_MUTEX_EVENT:
313-
mbed_error_printf("Mutex: 0x%X, ", ctx->error_value);
317+
mbed_error_printf("Mutex: 0x%" PRIX32 ", ", ctx->error_value);
314318
break;
315319

316320
case MBED_ERROR_CODE_RTOS_SEMAPHORE_EVENT:
317-
mbed_error_printf("Semaphore: 0x%X, ", ctx->error_value);
321+
mbed_error_printf("Semaphore: 0x%" PRIX32 ", ", ctx->error_value);
318322
break;
319323

320324
case MBED_ERROR_CODE_RTOS_MEMORY_POOL_EVENT:
321-
mbed_error_printf("MemoryPool: 0x%X, ", ctx->error_value);
325+
mbed_error_printf("MemoryPool: 0x%" PRIX32 ", ", ctx->error_value);
322326
break;
323327

324328
case MBED_ERROR_CODE_RTOS_EVENT_FLAGS_EVENT:
325-
mbed_error_printf("EventFlags: 0x%X, ", ctx->error_value);
329+
mbed_error_printf("EventFlags: 0x%" PRIX32 ", ", ctx->error_value);
326330
break;
327331

328332
case MBED_ERROR_CODE_RTOS_TIMER_EVENT:
329-
mbed_error_printf("Timer: 0x%X, ", ctx->error_value);
333+
mbed_error_printf("Timer: 0x%" PRIX32 ", ", ctx->error_value);
330334
break;
331335

332336
case MBED_ERROR_CODE_RTOS_MESSAGE_QUEUE_EVENT:
333-
mbed_error_printf("MessageQueue: 0x%X, ", ctx->error_value);
337+
mbed_error_printf("MessageQueue: 0x%" PRIX32 ", ", ctx->error_value);
334338
break;
335339

336340
case MBED_ERROR_CODE_ASSERTION_FAILED:
@@ -342,7 +346,7 @@ static void print_error_report(const mbed_error_ctx *ctx, const char *error_msg,
342346
break;
343347
}
344348
mbed_error_puts(error_msg);
345-
mbed_error_printf("\nLocation: 0x%X", ctx->error_address);
349+
mbed_error_printf("\nLocation: 0x%" PRIX32, ctx->error_address);
346350

347351
/* We print the filename passed in, not any filename in the context. This
348352
* avoids the console print for mbed_error being limited to the presence
@@ -357,9 +361,9 @@ static void print_error_report(const mbed_error_ctx *ctx, const char *error_msg,
357361
mbed_error_printf("+%d", error_line);
358362
}
359363

360-
mbed_error_printf("\nError Value: 0x%X", ctx->error_value);
364+
mbed_error_printf("\nError Value: 0x%" PRIX32, ctx->error_value);
361365
#ifdef MBED_CONF_RTOS_PRESENT
362-
mbed_error_printf("\nCurrent Thread: %s Id: 0x%X Entry: 0x%X StackSize: 0x%X StackMem: 0x%X SP: 0x%X ",
366+
mbed_error_printf("\nCurrent Thread: %s Id: 0x%" PRIX32 " Entry: 0x%" PRIX32 " StackSize: 0x%" PRIX32 " StackMem: 0x%" PRIX32 " SP: 0x%" PRIX32 " ",
363367
name_or_unnamed(((osRtxThread_t *)ctx->thread_id)->name),
364368
ctx->thread_id, ctx->thread_entry_address, ctx->thread_stack_size, ctx->thread_stack_mem, ctx->thread_current_sp);
365369
#endif

0 commit comments

Comments
 (0)