From d0d111356f36373bdda387626162f60b38f2177a Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sat, 21 Jun 2025 15:40:38 +0200 Subject: py: Fix mp_printf integer size mismatches. The type of the argument must match the format string. Add casts to ensure that they do. It's possible that casting from `size_t` to `unsigned` loses the correct values by masking off upper bits, but it seems likely that the quantities involved in practice are small enough that the `%u` formatter (32 bits on most platforms, 16 on pic16bit) will in fact hold the correct value. The alternative, casting to a wider type, adds code size. These locations were found using an experimental gcc plugin for `mp_printf` error checking, cross-building for x64 windows on Linux. In one case there was already a cast, but it was written incorrectly and did not have the intended effect. Signed-off-by: Jeff Epler --- py/modmicropython.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'py/modmicropython.c') diff --git a/py/modmicropython.c b/py/modmicropython.c index d1a687f10..4d676cb4a 100644 --- a/py/modmicropython.c +++ b/py/modmicropython.c @@ -98,7 +98,7 @@ static mp_obj_t mp_micropython_qstr_info(size_t n_args, const mp_obj_t *args) { size_t n_pool, n_qstr, n_str_data_bytes, n_total_bytes; qstr_pool_info(&n_pool, &n_qstr, &n_str_data_bytes, &n_total_bytes); mp_printf(&mp_plat_print, "qstr pool: n_pool=%u, n_qstr=%u, n_str_data_bytes=%u, n_total_bytes=%u\n", - n_pool, n_qstr, n_str_data_bytes, n_total_bytes); + (uint)n_pool, (uint)n_qstr, (uint)n_str_data_bytes, (uint)n_total_bytes); if (n_args == 1) { // arg given means dump qstr data qstr_dump_data(); -- cgit v1.2.3