]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix usage og PyUnicode_READY()
authorVictor Stinner <victor.stinner@haypocalc.com>
Tue, 4 Oct 2011 18:53:03 +0000 (20:53 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Tue, 4 Oct 2011 18:53:03 +0000 (20:53 +0200)
Modules/_io/stringio.c
Objects/unicodeobject.c
Python/getargs.c

index c40163f4def4c5a7fa6b95d772b068f8a0f8331a..a4536b1b07c41d9dca0d9600a4d756a857e6e137 100644 (file)
@@ -131,6 +131,10 @@ write_str(stringio *self, PyObject *obj)
         return -1;
 
     assert(PyUnicode_Check(decoded));
+    if (PyUnicode_READY(decoded)) {
+        Py_DECREF(decoded);
+        return -1;
+    }
     len = PyUnicode_GET_LENGTH(decoded);
 
     assert(len >= 0);
index b628eeb93a83e91d9960b5c2151dd5ef51ea03c3..cd67f60906be32b6dd688c050005f06c452b9f31 100644 (file)
@@ -2120,6 +2120,10 @@ PyUnicode_FromFormatV(const char *format, va_list vargs)
                     str_obj = PyUnicode_DecodeUTF8(str, strlen(str), "replace");
                     if (!str_obj)
                         goto fail;
+                    if (PyUnicode_READY(str_obj)) {
+                        Py_DECREF(str_obj);
+                        goto fail;
+                    }
                     argmaxchar = PyUnicode_MAX_CHAR_VALUE(str_obj);
                     maxchar = Py_MAX(maxchar, argmaxchar);
                     n += PyUnicode_GET_LENGTH(str_obj);
@@ -10062,17 +10066,17 @@ PyUnicode_Append(PyObject **p_left, PyObject *right)
         goto error;
     }
 
+    if (PyUnicode_READY(left))
+        goto error;
+    if (PyUnicode_READY(right))
+        goto error;
+
     if (PyUnicode_CheckExact(left) && left != unicode_empty
         && PyUnicode_CheckExact(right) && right != unicode_empty
         && unicode_resizable(left)
         && (_PyUnicode_KIND(right) <= _PyUnicode_KIND(left)
             || _PyUnicode_WSTR(left) != NULL))
     {
-        if (PyUnicode_READY(left))
-            goto error;
-        if (PyUnicode_READY(right))
-            goto error;
-
         /* Don't resize for ascii += latin1. Convert ascii to latin1 requires
            to change the structure size, but characters are stored just after
            the structure, and so it requires to move all charactres which is
index 0e7d9c43506497622de6af5d009dc8aaba73534e..2c2db36193c8bf6e20558d471d0d7016a4115cd0 100644 (file)
@@ -834,14 +834,21 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
 
     case 'C': {/* unicode char */
         int *p = va_arg(*p_va, int *);
-        if (PyUnicode_Check(arg) &&
-            PyUnicode_GET_LENGTH(arg) == 1) {
-            int kind = PyUnicode_KIND(arg);
-            void *data = PyUnicode_DATA(arg);
-            *p = PyUnicode_READ(kind, data, 0);
-        }
-        else
+        int kind;
+        void *data;
+
+        if (!PyUnicode_Check(arg))
+            return converterr("a unicode character", arg, msgbuf, bufsize);
+
+        if (PyUnicode_READY(arg))
+            RETURN_ERR_OCCURRED;
+
+        if (PyUnicode_GET_LENGTH(arg) != 1)
             return converterr("a unicode character", arg, msgbuf, bufsize);
+
+        kind = PyUnicode_KIND(arg);
+        data = PyUnicode_DATA(arg);
+        *p = PyUnicode_READ(kind, data, 0);
         break;
     }