diff options
author | Sergey Fedoseev <fedoseev.sergey@gmail.com> | 2020-05-25 14:54:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-25 14:54:40 (GMT) |
commit | e682b26a6bc6d3db1a44d82db09d26224e82ccb5 (patch) | |
tree | e680c94323d9a5e31b8f8cefd16710a8243a8078 /Objects/listobject.c | |
parent | ef16958d17e83723334a51428f410f726d6492a7 (diff) | |
download | cpython-e682b26a6bc6d3db1a44d82db09d26224e82ccb5.zip cpython-e682b26a6bc6d3db1a44d82db09d26224e82ccb5.tar.gz cpython-e682b26a6bc6d3db1a44d82db09d26224e82ccb5.tar.bz2 |
bpo-34397: Remove redundant overflow checks in list and tuple implementation. (GH-8757)
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r-- | Objects/listobject.c | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index 37fadca..30d2620 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -261,12 +261,8 @@ ins1(PyListObject *self, Py_ssize_t where, PyObject *v) PyErr_BadInternalCall(); return -1; } - if (n == PY_SSIZE_T_MAX) { - PyErr_SetString(PyExc_OverflowError, - "cannot add more objects to list"); - return -1; - } + assert((size_t)n + 1 < PY_SSIZE_T_MAX); if (list_resize(self, n+1) < 0) return -1; @@ -301,12 +297,7 @@ app1(PyListObject *self, PyObject *v) Py_ssize_t n = PyList_GET_SIZE(self); assert (v != NULL); - if (n == PY_SSIZE_T_MAX) { - PyErr_SetString(PyExc_OverflowError, - "cannot add more objects to list"); - return -1; - } - + assert((size_t)n + 1 < PY_SSIZE_T_MAX); if (list_resize(self, n+1) < 0) return -1; @@ -503,8 +494,7 @@ list_concat(PyListObject *a, PyObject *bb) return NULL; } #define b ((PyListObject *)bb) - if (Py_SIZE(a) > PY_SSIZE_T_MAX - Py_SIZE(b)) - return PyErr_NoMemory(); + assert((size_t)Py_SIZE(a) + (size_t)Py_SIZE(b) < PY_SSIZE_T_MAX); size = Py_SIZE(a) + Py_SIZE(b); np = (PyListObject *) list_new_prealloc(size); if (np == NULL) { |