[Python-checkins] bpo-34910: Ensure that PyObject_Print() always returns -1 on error. (GH-9733)

Miss Islington (bot) webhook-mailer at python.org
Sat Oct 6 03:07:15 EDT 2018


https://github.com/python/cpython/commit/49fb49d6f57661f2a7601f1d759163866f707fed
commit: 49fb49d6f57661f2a7601f1d759163866f707fed
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2018-10-06T00:07:12-07:00
summary:

bpo-34910: Ensure that PyObject_Print() always returns -1 on error. (GH-9733)

(cherry picked from commit ae62f015240c9162773341a9922794e6b960779d)

Co-authored-by: Zackery Spytz <zspytz at gmail.com>

files:
A Misc/NEWS.d/next/C API/2018-10-05-17-06-49.bpo-34910.tSFrls.rst
M Objects/object.c

diff --git a/Misc/NEWS.d/next/C API/2018-10-05-17-06-49.bpo-34910.tSFrls.rst b/Misc/NEWS.d/next/C API/2018-10-05-17-06-49.bpo-34910.tSFrls.rst
new file mode 100644
index 000000000000..eff4755d8d5e
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2018-10-05-17-06-49.bpo-34910.tSFrls.rst	
@@ -0,0 +1,2 @@
+Ensure that :c:func:`PyObject_Print` always returns ``-1`` on error.  Patch
+by Zackery Spytz.
diff --git a/Objects/object.c b/Objects/object.c
index 220aa90bf59c..5535b7ee7eca 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -376,8 +376,9 @@ PyObject_Print(PyObject *op, FILE *fp, int flags)
             else if (PyUnicode_Check(s)) {
                 PyObject *t;
                 t = PyUnicode_AsEncodedString(s, "utf-8", "backslashreplace");
-                if (t == NULL)
-                    ret = 0;
+                if (t == NULL) {
+                    ret = -1;
+                }
                 else {
                     fwrite(PyBytes_AS_STRING(t), 1,
                            PyBytes_GET_SIZE(t), fp);



More information about the Python-checkins mailing list