]> granicus.if.org Git - python/commitdiff
Fix resize_compact()
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 27 Jan 2016 15:56:53 +0000 (16:56 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 27 Jan 2016 15:56:53 +0000 (16:56 +0100)
Issue #26217: resize_compact() must set wstr_length to 0 after freeing the wstr
string. Otherwise, an assertion fails in _PyUnicode_CheckConsistency().

Objects/unicodeobject.c

index c95792946d5bc3af6f87755effe88c875edcb715..d4c9aaee217cb380cf8127bdff3ee012dda59180 100644 (file)
@@ -748,6 +748,8 @@ resize_compact(PyObject *unicode, Py_ssize_t length)
     else if (_PyUnicode_HAS_WSTR_MEMORY(unicode)) {
         PyObject_DEL(_PyUnicode_WSTR(unicode));
         _PyUnicode_WSTR(unicode) = NULL;
+        if (!PyUnicode_IS_ASCII(unicode))
+            _PyUnicode_WSTR_LENGTH(unicode) = 0;
     }
 #ifdef Py_DEBUG
     unicode_fill_invalid(unicode, old_length);