Skip to content

Commit 177254c

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 <[email protected]>
1 parent 22e86fb commit 177254c

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed
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
@@ -387,8 +387,9 @@ PyObject_Print(PyObject *op, FILE *fp, int flags)
387387
else if (PyUnicode_Check(s)) {
388388
PyObject *t;
389389
t = PyUnicode_AsEncodedString(s, "utf-8", "backslashreplace");
390-
if (t == NULL)
391-
ret = 0;
390+
if (t == NULL) {
391+
ret = -1;
392+
}
392393
else {
393394
fwrite(PyBytes_AS_STRING(t), 1,
394395
PyBytes_GET_SIZE(t), fp);

0 commit comments

Comments
 (0)