Fixing a couple of long standing bugs.
authorAndrey Hristov <andrey@php.net>
Wed, 26 May 1999 18:45:53 +0000 (18:45 +0000)
committerAndrey Hristov <andrey@php.net>
Wed, 26 May 1999 18:45:53 +0000 (18:45 +0000)
ext/ereg/ereg.c
ext/standard/reg.c

index bd049e1fb09c3a189adaaa1b2fb6dc1bc3b89b01..8a7d97c9bbc3401ae1c45bd2cd9493291540689e 100644 (file)
@@ -563,7 +563,7 @@ PHP_FUNCTION(split)
        }
 
        /* churn through str, generating array entries as we go */
-       while ((count == -1 || count > 1) && !(err = regexec(&re, strp, 1, subs, 0))) {
+       while ((count == -1 || count > 0) && !(err = regexec(&re, strp, 1, subs, 0))) {
                if (subs[0].rm_so == 0 && subs[0].rm_eo) {
                        /* match is at start of string, return empty string */
                        add_next_index_stringl(return_value, empty_string, 0, 1);
@@ -604,9 +604,11 @@ PHP_FUNCTION(split)
        }
 
        /* otherwise we just have one last element to add to the array */
-       size = endp - strp;
+       if (count == -1) {
+               size = endp - strp;
        
-       add_next_index_stringl(return_value, strp, size, 1);
+               add_next_index_stringl(return_value, strp, size, 1);
+       }
 
        regfree(&re);
 
index bd049e1fb09c3a189adaaa1b2fb6dc1bc3b89b01..8a7d97c9bbc3401ae1c45bd2cd9493291540689e 100644 (file)
@@ -563,7 +563,7 @@ PHP_FUNCTION(split)
        }
 
        /* churn through str, generating array entries as we go */
-       while ((count == -1 || count > 1) && !(err = regexec(&re, strp, 1, subs, 0))) {
+       while ((count == -1 || count > 0) && !(err = regexec(&re, strp, 1, subs, 0))) {
                if (subs[0].rm_so == 0 && subs[0].rm_eo) {
                        /* match is at start of string, return empty string */
                        add_next_index_stringl(return_value, empty_string, 0, 1);
@@ -604,9 +604,11 @@ PHP_FUNCTION(split)
        }
 
        /* otherwise we just have one last element to add to the array */
-       size = endp - strp;
+       if (count == -1) {
+               size = endp - strp;
        
-       add_next_index_stringl(return_value, strp, size, 1);
+               add_next_index_stringl(return_value, strp, size, 1);
+       }
 
        regfree(&re);