[Python-checkins] cpython: set_repr(): handle correctly PyUnicode_FromUnicode() error (MemoryError)
victor.stinner
python-checkins at python.org
Thu May 26 14:25:57 CEST 2011
http://hg.python.org/cpython/rev/8b819c982b36
changeset: 70401:8b819c982b36
user: Victor Stinner <victor.stinner at haypocalc.com>
date: Thu May 26 14:24:30 2011 +0200
summary:
set_repr(): handle correctly PyUnicode_FromUnicode() error (MemoryError)
Bug found by the Clang Static Analyzer.
files:
Objects/setobject.c | 20 +++++++++++---------
1 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/Objects/setobject.c b/Objects/setobject.c
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -607,16 +607,18 @@
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,
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list