summaryrefslogtreecommitdiff
path: root/py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-04-19 17:38:27 +1000
committerDamien George <damien.p.george@gmail.com>2019-04-23 12:40:15 +1000
commit27d22d8712d79636be7115d47c8872d6c1da749c (patch)
tree79231fab9667b53fa490e98ca0713fd93b5cb90c /py
parent8402c26cfa98b4689f5ac4673952a654cfe5b678 (diff)
py/mpprint: Support printing %ld and %lu formats on 64-bit archs.
Fixes issue #4702.
Diffstat (limited to 'py')
-rw-r--r--py/mpprint.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/py/mpprint.c b/py/mpprint.c
index 82e78f62f..cf09f7bbe 100644
--- a/py/mpprint.c
+++ b/py/mpprint.c
@@ -503,22 +503,28 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) {
chrs += mp_print_strn(print, str, prec, flags, fill, width);
break;
}
- case 'u':
- 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);
+ case 'd': {
+ mp_int_t val;
+ if (long_arg) {
+ val = va_arg(args, long int);
+ } else {
+ val = va_arg(args, int);
+ }
+ chrs += mp_print_int(print, val, 1, 10, 'a', flags, fill, width);
break;
+ }
+ case 'u':
case 'x':
case 'X': {
- char fmt_c = *fmt - 'X' + 'A';
+ int base = 16 - ((*fmt + 1) & 6); // maps char u/x/X to base 10/16/16
+ char fmt_c = (*fmt & 0xf0) - 'P' + 'A'; // maps char u/x/X to char a/a/A
mp_uint_t val;
if (long_arg) {
val = va_arg(args, unsigned long int);
} else {
val = va_arg(args, unsigned int);
}
- chrs += mp_print_int(print, val, 0, 16, fmt_c, flags, fill, width);
+ chrs += mp_print_int(print, val, 0, base, fmt_c, flags, fill, width);
break;
}
case 'p':