From 2a1cca20b1e1a93c86c8c3a3254ab7150c85ac08 Mon Sep 17 00:00:00 2001
From: Damien George <damien.p.george@gmail.com>
Date: Mon, 14 Mar 2016 22:40:39 +0000
Subject: [PATCH] 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.
---
 py/modbuiltins.c   | 2 +-
 py/obj.c           | 2 +-
 py/objclosure.c    | 2 +-
 py/objnamedtuple.c | 2 +-
 py/runtime.c       | 6 +++---
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/py/modbuiltins.c b/py/modbuiltins.c
index 05bdbfeca..859cb1111 100644
--- a/py/modbuiltins.c
+++ b/py/modbuiltins.c
@@ -370,7 +370,7 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) {
             "ord expects a character"));
     } else {
         nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError,
-            "ord() expected a character, but string of length %d found", len));
+            "ord() expected a character, but string of length %d found", (int)len));
     }
 }
 MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_ord_obj, mp_builtin_ord);
diff --git a/py/obj.c b/py/obj.c
index 65b447494..91dd4c090 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -342,7 +342,7 @@ void mp_obj_get_array_fixed_n(mp_obj_t o, mp_uint_t len, mp_obj_t **items) {
                 "tuple/list has wrong length"));
         } else {
             nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
-                "requested length %d but object has length %d", len, seq_len));
+                "requested length %d but object has length %d", (int)len, (int)seq_len));
         }
     }
 }
diff --git a/py/objclosure.c b/py/objclosure.c
index d556b3b8a..4b37d2dd1 100644
--- a/py/objclosure.c
+++ b/py/objclosure.c
@@ -65,7 +65,7 @@ STATIC void closure_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_
     mp_obj_closure_t *o = MP_OBJ_TO_PTR(o_in);
     mp_print_str(print, "<closure ");
     mp_obj_print_helper(print, o->fun, PRINT_REPR);
-    mp_printf(print, " at %p, n_closed=%u ", o, o->n_closed);
+    mp_printf(print, " at %p, n_closed=%u ", o, (int)o->n_closed);
     for (mp_uint_t i = 0; i < o->n_closed; i++) {
         if (o->closed[i] == MP_OBJ_NULL) {
             mp_print_str(print, "(nil)");
diff --git a/py/objnamedtuple.c b/py/objnamedtuple.c
index 62289f50f..76dc9a1fc 100644
--- a/py/objnamedtuple.c
+++ b/py/objnamedtuple.c
@@ -79,7 +79,7 @@ STATIC void namedtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
 
 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) {
     const mp_obj_namedtuple_type_t *type = (const mp_obj_namedtuple_type_t*)type_in;
-    mp_uint_t num_fields = type->n_fields;
+    size_t num_fields = type->n_fields;
     if (n_args + n_kw != num_fields) {
         if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
             mp_arg_error_terse_mismatch();
diff --git a/py/runtime.c b/py/runtime.c
index e4a4d5b3f..adbab579f 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -788,7 +788,7 @@ too_short:
             "wrong number of values to unpack"));
     } else {
         nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
-            "need more than %d values to unpack", seq_len));
+            "need more than %d values to unpack", (int)seq_len));
     }
 too_long:
     if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
@@ -796,7 +796,7 @@ too_long:
             "wrong number of values to unpack"));
     } else {
         nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
-            "too many values to unpack (expected %d)", num));
+            "too many values to unpack (expected %d)", (int)num));
     }
 }
 
@@ -863,7 +863,7 @@ too_short:
             "wrong number of values to unpack"));
     } else {
         nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError,
-            "need more than %d values to unpack", seq_len));
+            "need more than %d values to unpack", (int)seq_len));
     }
 }
 
-- 
GitLab