mirror of
https://github.com/python/cpython.git
synced 2025-12-10 02:50:09 +00:00
bpo-31619: Fixed a ValueError when convert a string with large number of underscores (#3827)
to integer with binary base.
This commit is contained in:
parent
1a87de7fcf
commit
85c0b8941f
3 changed files with 14 additions and 4 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue