diff Objects/stringobject.c @ 25100:bc590beadf0b legacy-trunk

Check whether a string resize is necessary at the end of PyString_DecodeEscape(). This prevents a call to _PyString_Resize() for the empty string, which would result in a PyErr_BadInternalCall(), because the empty string has more than one reference. This closes SF bug http://www.python.org/sf/603937
author Walter Dörwald <walter@livinglogic.de>
date Tue, 03 Sep 2002 13:53:40 +0000
parents 0337dad8403e
children f4e9f09df4f2
line wrap: on
line diff
--- a/Objects/stringobject.c	Tue Sep 03 13:25:17 2002 +0000
+++ b/Objects/stringobject.c	Tue Sep 03 13:53:40 2002 +0000
@@ -533,8 +533,8 @@
 	char *p, *buf;
 	const char *end;
 	PyObject *v;
-	v = PyString_FromStringAndSize((char *)NULL, 
-				       recode_encoding ? 4*len:len);
+	int newlen = recode_encoding ? 4*len:len;
+	v = PyString_FromStringAndSize((char *)NULL, newlen);
 	if (v == NULL)
 		return NULL;
 	p = buf = PyString_AsString(v);
@@ -660,7 +660,8 @@
 			break;
 		}
 	}
-	_PyString_Resize(&v, (int)(p - buf));
+	if (p-buf < newlen)
+		_PyString_Resize(&v, (int)(p - buf));
 	return v;
   failed:
 	Py_DECREF(v);