Skip to content

Commit a1a807b

Browse files
author
Victor Stinner
committed
set_repr(): handle correctly PyUnicode_FromUnicode() error (MemoryError)
Bug found by the Clang Static Analyzer.
1 parent 5572ba7 commit a1a807b

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

‎Objects/setobject.c‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -607,16 +607,18 @@ set_repr(PySetObject *so)
607607
goto done;
608608
newsize = PyUnicode_GET_SIZE(listrepr);
609609
result = PyUnicode_FromUnicode(NULL, newsize);
610-
if (result) {
611-
u = PyUnicode_AS_UNICODE(result);
612-
*u++ = '{';
613-
/* Omit the brackets from the listrepr */
614-
Py_UNICODE_COPY(u, PyUnicode_AS_UNICODE(listrepr)+1,
615-
newsize-2);
616-
u += newsize-2;
617-
*u = '}';
618-
}
610+
if (result == NULL)
611+
goto done;
612+
613+
u = PyUnicode_AS_UNICODE(result);
614+
*u++ = '{';
615+
/* Omit the brackets from the listrepr */
616+
Py_UNICODE_COPY(u, PyUnicode_AS_UNICODE(listrepr)+1,
617+
newsize-2);
618+
u += newsize-2;
619+
*u = '}';
619620
Py_DECREF(listrepr);
621+
620622
if (Py_TYPE(so) != &PySet_Type) {
621623
PyObject *tmp = PyUnicode_FromFormat("%s(%U)",
622624
Py_TYPE(so)->tp_name,

0 commit comments

Comments
 (0)