Skip to content

Commit d0d1113

Browse files
jeplerdpgeorge
authored andcommitted
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 <[email protected]>
1 parent 519cba4 commit d0d1113

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

py/gc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ void gc_dump_alloc_table(const mp_print_t *print) {
12021202
}
12031203
if (bl2 - bl >= 2 * DUMP_BYTES_PER_LINE) {
12041204
// there are at least 2 lines containing only free blocks, so abbreviate their printing
1205-
mp_printf(print, "\n (%u lines all free)", (uint)(bl2 - bl) / DUMP_BYTES_PER_LINE);
1205+
mp_printf(print, "\n (%u lines all free)", (uint)((bl2 - bl) / DUMP_BYTES_PER_LINE));
12061206
bl = bl2 & (~(DUMP_BYTES_PER_LINE - 1));
12071207
if (bl >= area->gc_alloc_table_byte_len * BLOCKS_PER_ATB) {
12081208
// got to end of heap

py/modmicropython.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static mp_obj_t mp_micropython_qstr_info(size_t n_args, const mp_obj_t *args) {
9898
size_t n_pool, n_qstr, n_str_data_bytes, n_total_bytes;
9999
qstr_pool_info(&n_pool, &n_qstr, &n_str_data_bytes, &n_total_bytes);
100100
mp_printf(&mp_plat_print, "qstr pool: n_pool=%u, n_qstr=%u, n_str_data_bytes=%u, n_total_bytes=%u\n",
101-
n_pool, n_qstr, n_str_data_bytes, n_total_bytes);
101+
(uint)n_pool, (uint)n_qstr, (uint)n_str_data_bytes, (uint)n_total_bytes);
102102
if (n_args == 1) {
103103
// arg given means dump qstr data
104104
qstr_dump_data();

0 commit comments

Comments
 (0)