diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2011-05-26 12:24:30 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2011-05-26 12:24:30 (GMT) |
commit | a1a807b6efdbdaa0af7da4aff46a4a205d87e8f9 (patch) | |
tree | 510ea4776cb20446d8d1e771a0233c9d7ddaf371 /Objects/setobject.c | |
parent | 5572ba7e15b462098aac2def8e85e59b055689c3 (diff) | |
download | cpython-a1a807b6efdbdaa0af7da4aff46a4a205d87e8f9.zip cpython-a1a807b6efdbdaa0af7da4aff46a4a205d87e8f9.tar.gz cpython-a1a807b6efdbdaa0af7da4aff46a4a205d87e8f9.tar.bz2 |
set_repr(): handle correctly PyUnicode_FromUnicode() error (MemoryError)
Bug found by the Clang Static Analyzer.
Diffstat (limited to 'Objects/setobject.c')
-rw-r--r-- | Objects/setobject.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c index 22243ea..ebfddb3 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -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, |