diff Objects/stringlib/count.h @ 38492:d5bdfd120232 legacy-trunk

fixed "abc".count("", 100) == -96 error (hopefully, nobody's relying on the current behaviour ;-)
author Fredrik Lundh <fredrik@pythonware.com>
date Mon, 29 May 2006 22:42:07 +0000
parents 5b0753b9d16a
children 2fe3233bd426
line wrap: on
line diff
--- a/Objects/stringlib/count.h	Mon May 29 22:00:30 2006 +0000
+++ b/Objects/stringlib/count.h	Mon May 29 22:42:07 2006 +0000
@@ -13,8 +13,11 @@
 {
     Py_ssize_t count;
 
-    if (sub_len == 0)
+    if (sub_len == 0) {
+        if (str_len < 0)
+            return 1; /* start >= len(str) */
         return str_len + 1;
+    }
 
     count = fastsearch(str, str_len, sub, sub_len, FAST_COUNT);