Commit b91ef008 authored by Benjamin Peterson's avatar Benjamin Peterson

add missing NULL check (closes #18019)

parent f41ffeda
......@@ -144,6 +144,11 @@ class DictSetTest(unittest.TestCase):
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)
......
......@@ -9,6 +9,9 @@ What's New in Python 2.7.6?
Core and Builtins
-----------------
- Issue #18019: Fix crash in the repr of dictionaries containing their own
views.
Library
-------
......
......@@ -2919,6 +2919,10 @@ dictview_repr(dictviewobject *dv)
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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment