From 1e596d3a20a1a9d1ef15218ef33795bc9e651b7a Mon Sep 17 00:00:00 2001 From: "Miss Islington (bot)" <31488909+miss-islington@users.noreply.github.com> Date: Sun, 19 Aug 2018 16:17:53 -0400 Subject: [PATCH] bpo-34435: Add missing NULL check to unicode_encode_ucs1(). (GH-8823) Reported by Svace static analyzer. (cherry picked from commit 74a307d48ef8b278c4629ca0ef2139be1c9a34e6) Co-authored-by: Alexey Izbyshev --- Objects/unicodeobject.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 5d605abd0327..fe833a76eadb 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -6812,8 +6812,6 @@ unicode_encode_ucs1(PyObject *unicode, str = _PyBytesWriter_WriteBytes(&writer, str, PyBytes_AS_STRING(rep), PyBytes_GET_SIZE(rep)); - if (str == NULL) - goto onError; } else { assert(PyUnicode_Check(rep)); @@ -6835,6 +6833,9 @@ unicode_encode_ucs1(PyObject *unicode, PyUnicode_DATA(rep), PyUnicode_GET_LENGTH(rep)); } + if (str == NULL) + goto onError; + pos = newpos; Py_CLEAR(rep); } -- 2.47.3