Skip to content

Commit 49fb49d

Browse files
bpo-34910: Ensure that PyObject_Print() always returns -1 on error. (GH-9733)
(cherry picked from commit ae62f01) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
1 parent 0991b9b commit 49fb49d

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Ensure that :c:func:`PyObject_Print` always returns ``-1`` on error. Patch
2+
by Zackery Spytz.

Objects/object.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,9 @@ PyObject_Print(PyObject *op, FILE *fp, int flags)
376376
else if (PyUnicode_Check(s)) {
377377
PyObject *t;
378378
t = PyUnicode_AsEncodedString(s, "utf-8", "backslashreplace");
379-
if (t == NULL)
380-
ret = 0;
379+
if (t == NULL) {
380+
ret = -1;
381+
}
381382
else {
382383
fwrite(PyBytes_AS_STRING(t), 1,
383384
PyBytes_GET_SIZE(t), fp);

0 commit comments

Comments
 (0)