diff Objects/unicodeobject.c @ 12957:97dd6dc33503 legacy-trunk

Marc-Andre Lemburg <mal@lemburg.com>: Fixed a bug in PyUnicode_Count() which would have caused a core dump in case of substring coercion failure. Synchronized .count() with the string method of the same name to return len(s)+1 for s.count('').
author Marc-André Lemburg <mal@egenix.com>
date Sun, 18 Jun 2000 22:25:22 +0000
parents 88004f25dc25
children 0be4b7b650e3
line wrap: on
line diff
--- a/Objects/unicodeobject.c	Sun Jun 18 22:22:27 2000 +0000
+++ b/Objects/unicodeobject.c	Sun Jun 18 22:25:22 2000 +0000
@@ -2106,6 +2106,9 @@
 {
     int count = 0;
 
+    if (substring->length == 0)
+	return (end - start + 1);
+
     end -= substring->length;
 
     while (start <= end)
@@ -2130,7 +2133,7 @@
 	return -1;
     substr = PyUnicode_FromObject(substr);
     if (substr == NULL) {
-	Py_DECREF(substr);
+	Py_DECREF(str);
 	return -1;
     }
     
@@ -3086,11 +3089,6 @@
     if (substring == NULL)
 	return NULL;
     
-    if (substring->length == 0) {
-	Py_DECREF(substring);
-        return PyInt_FromLong((long) 0);
-    }
-
     if (start < 0)
         start += self->length;
     if (start < 0)