[Python-checkins] cpython (3.3): Issue #16076: check for return value of PyTuple_New for args (following

eli.bendersky python-checkins at python.org
Sat Jan 12 14:43:32 CET 2013


http://hg.python.org/cpython/rev/4501813ea676
changeset:   81447:4501813ea676
branch:      3.3
parent:      81445:5b36768b9a11
user:        Eli Bendersky <eliben at gmail.com>
date:        Sat Jan 12 05:42:38 2013 -0800
summary:
  Issue #16076: check for return value of PyTuple_New for args (following
Coverity report) and cleanup code.

files:
  Modules/_elementtree.c |  23 +++++++++++++----------
  1 files changed, 13 insertions(+), 10 deletions(-)


diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -950,19 +950,22 @@
                              PICKLED_TAIL, PICKLED_CHILDREN, 0};
     PyObject *args;
     PyObject *tag, *attrib, *text, *tail, *children;
-    int error;
-
-    /* More instance dict members than we know to handle? */
+    PyObject *retval;
+
     tag = attrib = text = tail = children = NULL;
     args = PyTuple_New(0);
-    error = ! PyArg_ParseTupleAndKeywords(args, state, "|$OOOOO", kwlist, &tag,
-                                          &attrib, &text, &tail, &children);
+    if (!args)
+        return NULL;
+
+    if (PyArg_ParseTupleAndKeywords(args, state, "|$OOOOO", kwlist, &tag,
+                                    &attrib, &text, &tail, &children))
+        retval = element_setstate_from_attributes(self, tag, attrib, text,
+                                                  tail, children);
+    else
+        retval = NULL;
+
     Py_DECREF(args);
-    if (error)
-        return NULL;
-    else
-        return element_setstate_from_attributes(self, tag, attrib, text,
-                                                tail, children);
+    return retval;
 }
 
 static PyObject *

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list