summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Objects/weakrefobject.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/Objects/weakrefobject.c b/Objects/weakrefobject.c
index 8d571e6..417f075 100644
--- a/Objects/weakrefobject.c
+++ b/Objects/weakrefobject.c
@@ -167,13 +167,21 @@ weakref_repr(PyWeakReference *self)
PyErr_Clear();
else if (PyUnicode_Check(nameobj))
name = _PyUnicode_AsString(nameobj);
- PyOS_snprintf(buffer, sizeof(buffer),
- name ? "<weakref at %p; to '%.50s' at %p (%s)>"
- : "<weakref at %p; to '%.50s' at %p>",
- self,
- Py_TYPE(PyWeakref_GET_OBJECT(self))->tp_name,
- PyWeakref_GET_OBJECT(self),
- name);
+ if (name != NULL) {
+ PyOS_snprintf(buffer, sizeof(buffer),
+ "<weakref at %p; to '%.50s' at %p (%s)>",
+ self,
+ Py_TYPE(PyWeakref_GET_OBJECT(self))->tp_name,
+ PyWeakref_GET_OBJECT(self),
+ name);
+ }
+ else {
+ PyOS_snprintf(buffer, sizeof(buffer),
+ "<weakref at %p; to '%.50s' at %p>",
+ self,
+ Py_TYPE(PyWeakref_GET_OBJECT(self))->tp_name,
+ PyWeakref_GET_OBJECT(self));
+ }
Py_XDECREF(nameobj);
}
return PyUnicode_FromString(buffer);