diff options
Diffstat (limited to 'Objects')
| -rw-r--r-- | Objects/longobject.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c index 3b07585..c71b783 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -2057,15 +2057,15 @@ long_from_binary_base(const char **str, int base, PyLongObject **res) } *str = p; - /* n <- # of Python digits needed, = ceiling(n/PyLong_SHIFT). */ - n = digits * bits_per_char + PyLong_SHIFT - 1; - if (n / bits_per_char < p - start) { + /* n <- the number of Python digits needed, + = ceiling((digits * bits_per_char) / PyLong_SHIFT). */ + if (digits > (PY_SSIZE_T_MAX - (PyLong_SHIFT - 1)) / bits_per_char) { PyErr_SetString(PyExc_ValueError, "int string too large to convert"); *res = NULL; return 0; } - n = n / PyLong_SHIFT; + n = (digits * bits_per_char + PyLong_SHIFT - 1) / PyLong_SHIFT; z = _PyLong_New(n); if (z == NULL) { *res = NULL; |
