py/mpprint: Fix sign extension when printf'ing %u, %x and %X.

pull/1808/merge
Damien George 2016-02-01 15:08:42 +00:00
rodzic 331a48195d
commit 9e677114e4
3 zmienionych plików z 11 dodań i 3 usunięć

Wyświetl plik

@ -494,16 +494,16 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) {
break; break;
} }
case 'u': 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; break;
case 'd': case 'd':
chrs += mp_print_int(print, va_arg(args, int), 1, 10, 'a', flags, fill, width); chrs += mp_print_int(print, va_arg(args, int), 1, 10, 'a', flags, fill, width);
break; break;
case 'x': 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; break;
case 'X': 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; break;
case 'p': case 'p':
case 'P': // don't bother to handle upcase for 'P' case 'P': // don't bother to handle upcase for 'P'

Wyświetl plik

@ -8,6 +8,10 @@ ab abc
false true false true
(null) (null)
t t
-2147483648
2147483648
80000000
80000000
# vstr # vstr
tests tests
sts sts

Wyświetl plik

@ -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, "%b %b\n", 0, 1); // bools
mp_printf(&mp_plat_print, "%s\n", NULL); // null string 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, "%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 // vstr