Skip to content

Commit 5e51ebf

Browse files
committed
pythongh-125196: PyUnicodeWriter_Discard(NULL) does nothing
1 parent 52f70da commit 5e51ebf

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

Doc/c-api/unicode.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,6 +1600,8 @@ object.
16001600
16011601
Discard the internal Unicode buffer and destroy the writer instance.
16021602
1603+
Do nothing if *writer* is ``NULL``.
1604+
16031605
.. c:function:: int PyUnicodeWriter_WriteChar(PyUnicodeWriter *writer, Py_UCS4 ch)
16041606
16051607
Write the single Unicode character *ch* into *writer*.

Objects/listobject.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,7 @@ list_repr_impl(PyListObject *v)
563563
return PyUnicodeWriter_Finish(writer);
564564

565565
error:
566-
if (writer != NULL) {
567-
PyUnicodeWriter_Discard(writer);
568-
}
566+
PyUnicodeWriter_Discard(writer);
569567
Py_ReprLeave((PyObject *)v);
570568
return NULL;
571569
}

Objects/unicodeobject.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13455,6 +13455,9 @@ PyUnicodeWriter_Create(Py_ssize_t length)
1345513455

1345613456
void PyUnicodeWriter_Discard(PyUnicodeWriter *writer)
1345713457
{
13458+
if (writer == NULL) {
13459+
return;
13460+
}
1345813461
_PyUnicodeWriter_Dealloc((_PyUnicodeWriter*)writer);
1345913462
PyMem_Free(writer);
1346013463
}

0 commit comments

Comments
 (0)