]> granicus.if.org Git - python/commitdiff
set_repr(): handle correctly PyUnicode_FromUnicode() error (MemoryError)
authorVictor Stinner <victor.stinner@haypocalc.com>
Thu, 26 May 2011 12:24:30 +0000 (14:24 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Thu, 26 May 2011 12:24:30 +0000 (14:24 +0200)
Bug found by the Clang Static Analyzer.

Objects/setobject.c

index 22243eaa6c03f63a4a5ff9a1a6049971869a0f44..ebfddb398ccc5afa2d87e073fe2521a5902f60e4 100644 (file)
@@ -607,16 +607,18 @@ set_repr(PySetObject *so)
         goto done;
     newsize = PyUnicode_GET_SIZE(listrepr);
     result = PyUnicode_FromUnicode(NULL, newsize);
-    if (result) {
-        u = PyUnicode_AS_UNICODE(result);
-        *u++ = '{';
-        /* Omit the brackets from the listrepr */
-        Py_UNICODE_COPY(u, PyUnicode_AS_UNICODE(listrepr)+1,
-                           newsize-2);
-        u += newsize-2;
-        *u = '}';
-    }
+    if (result == NULL)
+        goto done;
+
+    u = PyUnicode_AS_UNICODE(result);
+    *u++ = '{';
+    /* Omit the brackets from the listrepr */
+    Py_UNICODE_COPY(u, PyUnicode_AS_UNICODE(listrepr)+1,
+                       newsize-2);
+    u += newsize-2;
+    *u = '}';
     Py_DECREF(listrepr);
+
     if (Py_TYPE(so) != &PySet_Type) {
         PyObject *tmp = PyUnicode_FromFormat("%s(%U)",
                                              Py_TYPE(so)->tp_name,