From 16cb329a27acf161b2db78a8b60e89e600c42f1b Mon Sep 17 00:00:00 2001 From: Martin Panter Date: Sat, 14 Jan 2017 06:30:37 +0000 Subject: Issue #1621: Overflow should not be possible in listextend() --- Objects/listobject.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'Objects/listobject.c') diff --git a/Objects/listobject.c b/Objects/listobject.c index dcd7b5efe5..05dddfc6d7 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -804,6 +804,9 @@ listextend(PyListObject *self, PyObject *b) Py_RETURN_NONE; } m = Py_SIZE(self); + /* It should not be possible to allocate a list large enough to cause + an overflow on any relevant platform */ + assert(m < PY_SSIZE_T_MAX - n); if (list_resize(self, m + n) < 0) { Py_DECREF(b); return NULL; -- cgit v1.2.1 From 8f993e3ac6565928b14ffc0fcef23775f1b1e3f5 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 21 Jan 2017 23:05:00 +0200 Subject: Issue #29331: Simplified argument parsing in sorted() and list.sort(). --- Objects/listobject.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'Objects/listobject.c') diff --git a/Objects/listobject.c b/Objects/listobject.c index 05dddfc6d7..b21f637c56 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -1912,7 +1912,7 @@ reverse_sortslice(sortslice *s, Py_ssize_t n) * duplicated). */ static PyObject * -listsort(PyListObject *self, PyObject *args, PyObject *kwds) +listsort_impl(PyListObject *self, PyObject *keyfunc, int reverse) { MergeState ms; Py_ssize_t nremaining; @@ -1922,24 +1922,11 @@ listsort(PyListObject *self, PyObject *args, PyObject *kwds) PyObject **saved_ob_item; PyObject **final_ob_item; PyObject *result = NULL; /* guilty until proved innocent */ - int reverse = 0; - PyObject *keyfunc = NULL; Py_ssize_t i; - static char *kwlist[] = {"key", "reverse", 0}; PyObject **keys; assert(self != NULL); assert (PyList_Check(self)); - if (args != NULL) { - if (!PyArg_ParseTupleAndKeywords(args, kwds, "|Oi:sort", - kwlist, &keyfunc, &reverse)) - return NULL; - if (Py_SIZE(args) > 0) { - PyErr_SetString(PyExc_TypeError, - "must use keyword argument for key function"); - return NULL; - } - } if (keyfunc == Py_None) keyfunc = NULL; @@ -2088,6 +2075,19 @@ keyfunc_fail: #undef IFLT #undef ISLT +static PyObject * +listsort(PyListObject *self, PyObject *args, PyObject *kwds) +{ + static char *kwlist[] = {"key", "reverse", 0}; + PyObject *keyfunc = NULL; + int reverse = 0; + + if (!PyArg_ParseTupleAndKeywords(args, kwds, "|$Oi:sort", + kwlist, &keyfunc, &reverse)) + return NULL; + return listsort_impl(self, keyfunc, reverse); +} + int PyList_Sort(PyObject *v) { @@ -2095,7 +2095,7 @@ PyList_Sort(PyObject *v) PyErr_BadInternalCall(); return -1; } - v = listsort((PyListObject *)v, (PyObject *)NULL, (PyObject *)NULL); + v = listsort_impl((PyListObject *)v, NULL, 0); if (v == NULL) return -1; Py_DECREF(v); -- cgit v1.2.1 From bfeec6d871e3db2e0ddfdef01387913bc19cadd4 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Mon, 23 Jan 2017 09:47:21 +0200 Subject: Issue #28999: Use Py_RETURN_NONE, Py_RETURN_TRUE and Py_RETURN_FALSE wherever possible. Patch is writen with Coccinelle. --- Objects/listobject.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'Objects/listobject.c') diff --git a/Objects/listobject.c b/Objects/listobject.c index b21f637c56..89941749d4 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -2284,12 +2284,10 @@ list_richcompare(PyObject *v, PyObject *w, int op) /* We have an item that differs -- shortcuts for EQ/NE */ if (op == Py_EQ) { - Py_INCREF(Py_False); - return Py_False; + Py_RETURN_FALSE; } if (op == Py_NE) { - Py_INCREF(Py_True); - return Py_True; + Py_RETURN_TRUE; } /* Compare the final item again using the proper operator */ -- cgit v1.2.1