From c91e091ad72e3e15ca8981bd953f64714a5afb3e Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 15 Aug 2025 08:01:12 -0500 Subject: [PATCH] py/runtime: Fix printing of failed allocation amounts. On LP64 and LLP64 systems, size_t is bigger than unsigned. Printing the failed allocation using the new SIZE_FMT macro allows the correct failed allocation size to be shown. Example where this affects the failed allocation message (on x86_64 coverage build): >>> "a" * (1 << 54) Before, this would print the size as 1. Now it prints it as 18014398509481985 (2**54 + 1). Signed-off-by: Jeff Epler --- py/runtime.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/py/runtime.c b/py/runtime.c index 58d5732be1..a84e22760b 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -1669,14 +1669,14 @@ mp_obj_t mp_parse_compile_execute(mp_lexer_t *lex, mp_parse_input_kind_t parse_i #endif // MICROPY_ENABLE_COMPILER MP_NORETURN void m_malloc_fail(size_t num_bytes) { - DEBUG_printf("memory allocation failed, allocating %u bytes\n", (uint)num_bytes); + DEBUG_printf("memory allocation failed, allocating " SIZE_FMT " bytes\n", num_bytes); #if MICROPY_ENABLE_GC if (gc_is_locked()) { mp_raise_msg(&mp_type_MemoryError, MP_ERROR_TEXT("memory allocation failed, heap is locked")); } #endif mp_raise_msg_varg(&mp_type_MemoryError, - MP_ERROR_TEXT("memory allocation failed, allocating %u bytes"), (uint)num_bytes); + MP_ERROR_TEXT("memory allocation failed, allocating " SIZE_FMT " bytes"), num_bytes); } #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NONE