[Python-checkins] cpython (2.7): add missing NULL check (closes #18019)
benjamin.peterson
python-checkins at python.org
Mon May 20 04:39:54 CEST 2013
http://hg.python.org/cpython/rev/3568f8f1ccac
changeset: 83853:3568f8f1ccac
branch: 2.7
parent: 83840:68d2337688c1
user: Benjamin Peterson <benjamin at python.org>
date: Sun May 19 19:38:12 2013 -0700
summary:
add missing NULL check (closes #18019)
files:
Lib/test/test_dictviews.py | 5 +++++
Misc/NEWS | 3 +++
Objects/dictobject.c | 4 ++++
3 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/Lib/test/test_dictviews.py b/Lib/test/test_dictviews.py
--- a/Lib/test/test_dictviews.py
+++ b/Lib/test/test_dictviews.py
@@ -144,6 +144,11 @@
self.assertEqual(d1.viewitems() ^ d3.viewitems(),
{('a', 1), ('b', 2), ('d', 4), ('e', 5)})
+ def test_recursive_repr(self):
+ d = {}
+ d[42] = d.viewvalues()
+ self.assertRaises(RuntimeError, repr, d)
+
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -9,6 +9,9 @@
Core and Builtins
-----------------
+- Issue #18019: Fix crash in the repr of dictionaries containing their own
+ views.
+
Library
-------
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -2919,6 +2919,10 @@
return NULL;
seq_str = PyObject_Repr(seq);
+ if (seq_str == NULL) {
+ Py_DECREF(seq);
+ return NULL;
+ }
result = PyString_FromFormat("%s(%s)", Py_TYPE(dv)->tp_name,
PyString_AS_STRING(seq_str));
Py_DECREF(seq_str);
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list