diff options
author | Damien George <damien.p.george@gmail.com> | 2016-12-28 12:45:33 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2016-12-28 12:45:33 +1100 |
commit | 44bf8e1f2b3a66e8da09331ac016fa7922d8453c (patch) | |
tree | dfdf28ba70745b969f0ad49a7becc909202c8ff6 /py | |
parent | ca7af9a77864c09f9461563cfcf48323abe8ea25 (diff) | |
download | micropython-44bf8e1f2b3a66e8da09331ac016fa7922d8453c.tar.gz micropython-44bf8e1f2b3a66e8da09331ac016fa7922d8453c.zip |
py/mpprint: Add assertion for, and comment about, valid base values.
Diffstat (limited to 'py')
-rw-r--r-- | py/mpprint.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/py/mpprint.c b/py/mpprint.c index 9ad0f3f9a0..72d1c55ca0 100644 --- a/py/mpprint.c +++ b/py/mpprint.c @@ -202,6 +202,11 @@ STATIC int mp_print_int(const mp_print_t *print, mp_uint_t x, int sgn, int base, } int mp_print_mp_int(const mp_print_t *print, mp_obj_t x, int base, int base_char, int flags, char fill, int width, int prec) { + // These are the only values for "base" that are required to be supported by this + // function, since Python only allows the user to format integers in these bases. + // If needed this function could be generalised to handle other values. + assert(base == 2 || base == 8 || base == 10 || base == 16); + if (!MP_OBJ_IS_INT(x)) { // This will convert booleans to int, or raise an error for // non-integer types. |