Skip to content

Commit 2a1cca2

Browse files
committed
py: Fix passing of some wide int types to printf varg format list.
Passing an mp_uint_t to a %d printf format is incorrect for builds where mp_uint_t is larger than word size (eg a nanboxing build). This patch adds some simple casting to int in these cases.
1 parent e7cd169 commit 2a1cca2

5 files changed

Lines changed: 7 additions & 7 deletions

File tree

py/modbuiltins.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
370370
"ord expects a character"));
371371
} else {
372372
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
373-
"ord() expected a character, but string of length %d found", len));
373+
"ord() expected a character, but string of length %d found", (int)len));
374374
}
375375
}
376376
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_ord_obj, mp_builtin_ord);

py/obj.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ void mp_obj_get_array_fixed_n(mp_obj_t o, mp_uint_t len, mp_obj_t **items) {
342342
"tuple/list has wrong length"));
343343
} else {
344344
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
345-
"requested length %d but object has length %d", len, seq_len));
345+
"requested length %d but object has length %d", (int)len, (int)seq_len));
346346
}
347347
}
348348
}

py/objclosure.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ STATIC void closure_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_
6565
mp_obj_closure_t *o = MP_OBJ_TO_PTR(o_in);
6666
mp_print_str(print, "<closure ");
6767
mp_obj_print_helper(print, o->fun, PRINT_REPR);
68-
mp_printf(print, " at %p, n_closed=%u ", o, o->n_closed);
68+
mp_printf(print, " at %p, n_closed=%u ", o, (int)o->n_closed);
6969
for (mp_uint_t i = 0; i < o->n_closed; i++) {
7070
if (o->closed[i] == MP_OBJ_NULL) {
7171
mp_print_str(print, "(nil)");

py/objnamedtuple.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ STATIC void namedtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
7979

8080
STATIC mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
8181
const mp_obj_namedtuple_type_t *type = (const mp_obj_namedtuple_type_t*)type_in;
82-
mp_uint_t num_fields = type->n_fields;
82+
size_t num_fields = type->n_fields;
8383
if (n_args + n_kw != num_fields) {
8484
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
8585
mp_arg_error_terse_mismatch();

py/runtime.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -788,15 +788,15 @@ void mp_unpack_sequence(mp_obj_t seq_in, mp_uint_t num, mp_obj_t *items) {
788788
"wrong number of values to unpack"));
789789
} else {
790790
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
791-
"need more than %d values to unpack", seq_len));
791+
"need more than %d values to unpack", (int)seq_len));
792792
}
793793
too_long:
794794
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
795795
nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError,
796796
"wrong number of values to unpack"));
797797
} else {
798798
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
799-
"too many values to unpack (expected %d)", num));
799+
"too many values to unpack (expected %d)", (int)num));
800800
}
801801
}
802802

@@ -863,7 +863,7 @@ void mp_unpack_ex(mp_obj_t seq_in, mp_uint_t num_in, mp_obj_t *items) {
863863
"wrong number of values to unpack"));
864864
} else {
865865
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
866-
"need more than %d values to unpack", seq_len));
866+
"need more than %d values to unpack", (int)seq_len));
867867
}
868868
}
869869

0 commit comments

Comments
 (0)