mirror of
https://github.com/python/cpython.git
synced 2025-08-24 02:35:59 +00:00
gh-121153: Fix some errors with use of _PyLong_CompactValue() (GH-121154)
* The result has type Py_ssize_t, not intptr_t. * Type cast between unsigned and signdet integer types should be explicit. * Downcasting should be explicit. * Fix integer overflow check in sum().
This commit is contained in:
parent
0759cecd9d
commit
18015451d0
2 changed files with 57 additions and 15 deletions
|
@ -2644,8 +2644,8 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start)
|
|||
b = PyLong_AsLongAndOverflow(item, &overflow);
|
||||
}
|
||||
if (overflow == 0 &&
|
||||
(i_result >= 0 ? (b <= LONG_MAX - i_result)
|
||||
: (b >= LONG_MIN - i_result)))
|
||||
(i_result >= 0 ? (b <= PY_SSIZE_T_MAX - i_result)
|
||||
: (b >= PY_SSIZE_T_MIN - i_result)))
|
||||
{
|
||||
i_result += b;
|
||||
Py_DECREF(item);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue