From 9e677114e4aba8fdb417350a87ce1af33cef127f Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 1 Feb 2016 15:08:42 +0000 Subject: [PATCH] py/mpprint: Fix sign extension when printf'ing %u, %x and %X. --- py/mpprint.c | 6 +++--- tests/unix/extra_coverage.py.exp | 4 ++++ unix/coverage.c | 4 ++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/py/mpprint.c b/py/mpprint.c index 206cf2aa5c..cb49b1227a 100644 --- a/py/mpprint.c +++ b/py/mpprint.c @@ -494,16 +494,16 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) { break; } case 'u': - chrs += mp_print_int(print, va_arg(args, int), 0, 10, 'a', flags, fill, width); + chrs += mp_print_int(print, va_arg(args, unsigned int), 0, 10, 'a', flags, fill, width); break; case 'd': chrs += mp_print_int(print, va_arg(args, int), 1, 10, 'a', flags, fill, width); break; case 'x': - chrs += mp_print_int(print, va_arg(args, int), 0, 16, 'a', flags, fill, width); + chrs += mp_print_int(print, va_arg(args, unsigned int), 0, 16, 'a', flags, fill, width); break; case 'X': - chrs += mp_print_int(print, va_arg(args, int), 0, 16, 'A', flags, fill, width); + chrs += mp_print_int(print, va_arg(args, unsigned int), 0, 16, 'A', flags, fill, width); break; case 'p': case 'P': // don't bother to handle upcase for 'P' diff --git a/tests/unix/extra_coverage.py.exp b/tests/unix/extra_coverage.py.exp index 973c8bb2ee..db282b152c 100644 --- a/tests/unix/extra_coverage.py.exp +++ b/tests/unix/extra_coverage.py.exp @@ -8,6 +8,10 @@ ab abc false true (null) t +-2147483648 +2147483648 +80000000 +80000000 # vstr tests sts diff --git a/unix/coverage.c b/unix/coverage.c index 94d0ad4cae..9d53725543 100644 --- a/unix/coverage.c +++ b/unix/coverage.c @@ -22,6 +22,10 @@ STATIC mp_obj_t extra_coverage(void) { mp_printf(&mp_plat_print, "%b %b\n", 0, 1); // bools mp_printf(&mp_plat_print, "%s\n", NULL); // null string mp_printf(&mp_plat_print, "%t\n"); // non-format char + mp_printf(&mp_plat_print, "%d\n", 0x80000000); // should print signed + mp_printf(&mp_plat_print, "%u\n", 0x80000000); // should print unsigned + mp_printf(&mp_plat_print, "%x\n", 0x80000000); // should print unsigned + mp_printf(&mp_plat_print, "%X\n", 0x80000000); // should print unsigned } // vstr