]> granicus.if.org Git - python/commitdiff
Rework _Py_DumpASCII() to make Coverity happy
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 23 Mar 2016 15:10:07 +0000 (16:10 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 23 Mar 2016 15:10:07 +0000 (16:10 +0100)
Python/traceback.c

index 32594823977c054ffe8cc264ee558818f8dd9cbe..62a6b1e1a23466b741f5ae5b1f13e58525e24a16 100644 (file)
@@ -545,23 +545,23 @@ _Py_DumpASCII(int fd, PyObject *text)
 
     size = ascii->length;
     kind = ascii->state.kind;
-    if (ascii->state.compact) {
+    if (kind == PyUnicode_WCHAR_KIND) {
+        wstr = ((PyASCIIObject *)text)->wstr;
+        if (wstr == NULL)
+            return;
+        size = ((PyCompactUnicodeObject *)text)->wstr_length;
+    }
+    else if (ascii->state.compact) {
         if (ascii->state.ascii)
             data = ((PyASCIIObject*)text) + 1;
         else
             data = ((PyCompactUnicodeObject*)text) + 1;
     }
-    else if (kind != PyUnicode_WCHAR_KIND) {
+    else {
         data = ((PyUnicodeObject *)text)->data.any;
         if (data == NULL)
             return;
     }
-    else {
-        wstr = ((PyASCIIObject *)text)->wstr;
-        if (wstr == NULL)
-            return;
-        size = ((PyCompactUnicodeObject *)text)->wstr_length;
-    }
 
     if (MAX_STRING_LENGTH < size) {
         size = MAX_STRING_LENGTH;