]> granicus.if.org Git - python/commitdiff
- Reindent a confusingly indented piece of code (no intended code changes
authorThomas Wouters <thomas@python.org>
Sun, 12 Mar 2006 00:29:36 +0000 (00:29 +0000)
committerThomas Wouters <thomas@python.org>
Sun, 12 Mar 2006 00:29:36 +0000 (00:29 +0000)
   there)
 - Add missing DECREFs of inner-scope 'temp' variable
 - Add various missing DECREFs by changing 'return NULL' into 'goto onError'
 - Avoid double DECREF when last _PyUnicode_Resize() fails

Coverity found one of the missing DECREFs, but oddly enough not the others.

Objects/unicodeobject.c

index b044d68ab72415181fbabe931f9de94914b3d3ac..52bff2dfcb38ada7242f319f3102206aafa0a02c 100644 (file)
@@ -7068,15 +7068,15 @@ PyObject *PyUnicode_Format(PyObject *format,
                         /* nothing to do */;
                     else if (PyString_Check(temp)) {
                         /* convert to string to Unicode */
-                   unicode = PyUnicode_Decode(PyString_AS_STRING(temp),
+                       unicode = PyUnicode_Decode(PyString_AS_STRING(temp),
                                                   PyString_GET_SIZE(temp),
-                                              NULL,
+                                                  NULL,
                                                   "strict");
-                   Py_DECREF(temp);
-                   temp = unicode;
-                   if (temp == NULL)
-                       goto onError;
-               }
+                       Py_DECREF(temp);
+                       temp = unicode;
+                       if (temp == NULL)
+                           goto onError;
+                   }
                    else {
                        Py_DECREF(temp);
                        PyErr_SetString(PyExc_TypeError,
@@ -7172,11 +7172,13 @@ PyObject *PyUnicode_Format(PyObject *format,
                reslen += rescnt;
                if (reslen < 0) {
                    Py_XDECREF(temp);
-                   Py_DECREF(result);
-                   return PyErr_NoMemory();
+                   PyErr_NoMemory();
+                   goto onError;
+               }
+               if (_PyUnicode_Resize(&result, reslen) < 0) {
+                   Py_XDECREF(temp);
+                   goto onError;
                }
-               if (_PyUnicode_Resize(&result, reslen) < 0)
-                   return NULL;
                res = PyUnicode_AS_UNICODE(result)
                    + reslen - rescnt;
            }
@@ -7226,6 +7228,7 @@ PyObject *PyUnicode_Format(PyObject *format,
            if (dict && (argidx < arglen) && c != '%') {
                PyErr_SetString(PyExc_TypeError,
                                "not all arguments converted during string formatting");
+                Py_XDECREF(temp);
                goto onError;
            }
            Py_XDECREF(temp);
@@ -7237,12 +7240,12 @@ PyObject *PyUnicode_Format(PyObject *format,
        goto onError;
     }
 
+    if (_PyUnicode_Resize(&result, reslen - rescnt) < 0)
+       goto onError;
     if (args_owned) {
        Py_DECREF(args);
     }
     Py_DECREF(uformat);
-    if (_PyUnicode_Resize(&result, reslen - rescnt) < 0)
-       goto onError;
     return (PyObject *)result;
 
  onError: