]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix the problem reported in
authorMichael W. Hudson <mwh@python.net>
Fri, 22 Feb 2002 13:44:43 +0000 (13:44 +0000)
committerMichael W. Hudson <mwh@python.net>
Fri, 22 Feb 2002 13:44:43 +0000 (13:44 +0000)
[ #495401 ] Build troubles: --with-pymalloc

in a slightly different manner to the trunk, as discussed on python-dev.

Objects/unicodeobject.c

index 68afaa05c85fb25c5e3c1a7932b0878d36f2ee9f..388cfc669acf18e62537e632d3682b7c04d9954d 100644 (file)
@@ -1171,7 +1171,6 @@ PyObject *PyUnicode_EncodeUTF8(const Py_UNICODE *s,
 {
     PyObject *v;
     char *p;
-    char *q;
     Py_UCS4 ch2;
     unsigned int cbAllocated = 3 * size;
     unsigned int cbWritten = 0;
@@ -1183,7 +1182,7 @@ PyObject *PyUnicode_EncodeUTF8(const Py_UNICODE *s,
     if (size == 0)
         return v;
 
-    p = q = PyString_AS_STRING(v);
+    p = PyString_AS_STRING(v);
     while (i < size) {
         Py_UCS4 ch = s[i++];
         if (ch < 0x80) {
@@ -1208,6 +1207,7 @@ PyObject *PyUnicode_EncodeUTF8(const Py_UNICODE *s,
                            cbAllocated += 4*10;
                             if (_PyString_Resize(&v, cbAllocated))
                                goto onError;
+                           p = PyString_AS_STRING(v) + cbWritten;
                         }
 
                         /* combine the two values */
@@ -1227,6 +1227,13 @@ PyObject *PyUnicode_EncodeUTF8(const Py_UNICODE *s,
             *p++ = (char)(0x80 | ((ch >> 6) & 0x3f));
             *p++ = (char)(0x80 | (ch & 0x3f));
         } else {
+           if (cbWritten >= (cbAllocated - 4)) {
+                   /* Provide enough room for some more large characters. */
+                   cbAllocated += 4*10;
+                   if (_PyString_Resize(&v, cbAllocated))
+                           goto onError;
+                   p = PyString_AS_STRING(v) + cbWritten;
+           }
             *p++ = 0xf0 | (ch>>18);
             *p++ = 0x80 | ((ch>>12) & 0x3f);
             *p++ = 0x80 | ((ch>>6) & 0x3f);
@@ -1235,7 +1242,7 @@ PyObject *PyUnicode_EncodeUTF8(const Py_UNICODE *s,
        }
     }
     *p = '\0';
-    if (_PyString_Resize(&v, p - q))
+    if (_PyString_Resize(&v, cbWritten))
        goto onError;
     return v;