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

(cherry picked from commit ae62f01524)

Co-authored-by: Zackery Spytz <zspytz@gmail.com>
This commit is contained in:
Miss Islington (bot) 2018-10-06 00:07:12 -07:00 committed by GitHub
parent 0991b9bb94
commit 49fb49d6f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View File

@ -0,0 +1,2 @@
Ensure that :c:func:`PyObject_Print` always returns ``-1`` on error. Patch
by Zackery Spytz.

View File

@ -376,8 +376,9 @@ PyObject_Print(PyObject *op, FILE *fp, int flags)
else if (PyUnicode_Check(s)) { else if (PyUnicode_Check(s)) {
PyObject *t; PyObject *t;
t = PyUnicode_AsEncodedString(s, "utf-8", "backslashreplace"); t = PyUnicode_AsEncodedString(s, "utf-8", "backslashreplace");
if (t == NULL) if (t == NULL) {
ret = 0; ret = -1;
}
else { else {
fwrite(PyBytes_AS_STRING(t), 1, fwrite(PyBytes_AS_STRING(t), 1,
PyBytes_GET_SIZE(t), fp); PyBytes_GET_SIZE(t), fp);