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 <izbyshev@users.noreply.github.com>
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 5d605ab..fe833a7 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -6812,8 +6812,6 @@
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 @@
PyUnicode_DATA(rep),
PyUnicode_GET_LENGTH(rep));
}
+ if (str == NULL)
+ goto onError;
+
pos = newpos;
Py_CLEAR(rep);
}