]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[Backport r51230 | neal.norwitz]
authorAndrew M. Kuchling <amk@amk.ca>
Tue, 3 Oct 2006 19:07:06 +0000 (19:07 +0000)
committerAndrew M. Kuchling <amk@amk.ca>
Tue, 3 Oct 2006 19:07:06 +0000 (19:07 +0000)
Check return of PyMem_MALLOC (garbage) is non-NULL.
Check seq in both portions of if/else.

Klocwork #289-290.

Objects/listobject.c

index b0bc6a8c3167f1b420f6cffcc7d935bf7e5066bd..40d46203d2235a9053af6da7aa5e945c333fee6f 100644 (file)
@@ -2550,6 +2550,10 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
 
                        garbage = (PyObject**)
                                PyMem_MALLOC(slicelength*sizeof(PyObject*));
+                       if (!garbage) {
+                               PyErr_NoMemory();
+                               return -1;
+                       }
 
                        /* drawing pictures might help
                           understand these for loops */
@@ -2598,9 +2602,9 @@ list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
                        else {
                                seq = PySequence_Fast(value,
                                        "must assign iterable to extended slice");
-                               if (!seq)
-                                       return -1;
                        }
+                       if (!seq)
+                               return -1;
 
                        if (PySequence_Fast_GET_SIZE(seq) != slicelength) {
                                PyErr_Format(PyExc_ValueError,