]> granicus.if.org Git - python/commitdiff
bpo-34435: Add missing NULL check to unicode_encode_ucs1(). (GH-8823)
authorAlexey Izbyshev <izbyshev@users.noreply.github.com>
Sun, 19 Aug 2018 18:52:04 +0000 (21:52 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 19 Aug 2018 18:52:04 +0000 (21:52 +0300)
Reported by Svace static analyzer.

Objects/unicodeobject.c

index 0460d184932ee02f5498c6bd56d17e7fd19a4f76..087cfca58d36c8ba4257fce8b68ec8ae24806e8d 100644 (file)
@@ -6813,8 +6813,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));
@@ -6836,6 +6834,9 @@ unicode_encode_ucs1(PyObject *unicode,
                                                     PyUnicode_DATA(rep),
                                                     PyUnicode_GET_LENGTH(rep));
                 }
+                if (str == NULL)
+                    goto onError;
+
                 pos = newpos;
                 Py_CLEAR(rep);
             }