Skip to content

Commit 44bf8e1

Browse files
committed
py/mpprint: Add assertion for, and comment about, valid base values.
1 parent ca7af9a commit 44bf8e1

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

py/mpprint.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,11 @@ STATIC int mp_print_int(const mp_print_t *print, mp_uint_t x, int sgn, int base,
202202
}
203203

204204
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) {
205+
// These are the only values for "base" that are required to be supported by this
206+
// function, since Python only allows the user to format integers in these bases.
207+
// If needed this function could be generalised to handle other values.
208+
assert(base == 2 || base == 8 || base == 10 || base == 16);
209+
205210
if (!MP_OBJ_IS_INT(x)) {
206211
// This will convert booleans to int, or raise an error for
207212
// non-integer types.

0 commit comments

Comments
 (0)