diff Objects/unicodeobject.c @ 13966:91ddeed12fa7 legacy-trunk

Fixed a couple of instances where a 0-length string was being resized after creation. 0-length strings are usually shared and _PyString_Resize() fails on these shared strings. Fixes [ Bug #111667 ] unicode core dump.
author Marc-André Lemburg <mal@egenix.com>
date Mon, 14 Aug 2000 11:29:19 +0000
parents 7a99450da2d6
children d0348a26b093
line wrap: on
line diff
--- a/Objects/unicodeobject.c	Mon Aug 14 06:21:26 2000 +0000
+++ b/Objects/unicodeobject.c	Mon Aug 14 11:29:19 2000 +0000
@@ -842,7 +842,7 @@
     if (v == NULL)
         return NULL;
     if (size == 0)
-        goto done;
+        return v;
 
     p = q = PyString_AS_STRING(v);
     while (i < size) {
@@ -892,8 +892,6 @@
     *p = '\0';
     if (_PyString_Resize(&v, p - q))
 	goto onError;
-
- done:
     return v;
 
  onError:
@@ -1082,7 +1080,7 @@
     if (byteorder == 0)
 	*p++ = 0xFEFF;
     if (size == 0)
-        goto done;
+        return v;
     if (byteorder == 0 ||
 #ifdef BYTEORDER_IS_LITTLE_ENDIAN	
 	byteorder == -1
@@ -1096,7 +1094,6 @@
 	    Py_UNICODE ch = *s++;
 	    *p++ = (ch >> 8) | (ch << 8);
 	}
- done:
     return v;
 }
 
@@ -1563,6 +1560,8 @@
     repr = PyString_FromStringAndSize(NULL, 6 * size);
     if (repr == NULL)
         return NULL;
+    if (size == 0)
+	return repr;
 
     p = q = PyString_AS_STRING(repr);
     while (size-- > 0) {
@@ -1662,9 +1661,12 @@
 {
     PyObject *repr;
     char *s, *start;
+
     repr = PyString_FromStringAndSize(NULL, size);
     if (repr == NULL)
         return NULL;
+    if (size == 0)
+	return repr;
 
     s = PyString_AS_STRING(repr);
     start = s;
@@ -1802,9 +1804,12 @@
 {
     PyObject *repr;
     char *s, *start;
+
     repr = PyString_FromStringAndSize(NULL, size);
     if (repr == NULL)
         return NULL;
+    if (size == 0)
+	return repr;
 
     s = PyString_AS_STRING(repr);
     start = s;
@@ -1890,7 +1895,7 @@
     repr = PyString_FromStringAndSize(NULL, mbcssize);
     if (repr == NULL)
         return NULL;
-    if (mbcssize==0)
+    if (mbcssize == 0)
         return repr;
 
     /* Do the conversion */
@@ -2067,6 +2072,8 @@
     v = PyString_FromStringAndSize(NULL, size);
     if (v == NULL)
         return NULL;
+    if (size == 0)
+	return v;
     s = PyString_AS_STRING(v);
     while (size-- > 0) {
 	Py_UNICODE ch = *p++;