]> granicus.if.org Git - php/commitdiff
Fixed bug 67043
authorTjerk Meesters <datibbaw@php.net>
Tue, 8 Apr 2014 23:33:55 +0000 (07:33 +0800)
committerTjerk Meesters <datibbaw@php.net>
Tue, 8 Apr 2014 23:33:55 +0000 (07:33 +0800)
NEWS
ext/standard/string.c
ext/standard/tests/strings/substr_compare.phpt

diff --git a/NEWS b/NEWS
index 29e6c89a8d96a624608fa9ab0af226832bcce3fe..53220d74bf36c95e62aafab9f13f98bd91014cd8 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,7 @@ PHP                                                                        NEWS
     UNIX sockets). (Mike)
   . Fixed bug #66182 (exit in stream filter produces segfault). (Mike)  
   . Fixed bug #66736 (fpassthru broken). (Mike)
+  . Fixed bug #67043 (substr_compare broke by previous change) (Tjerk)
 
 - Embed:
   . Fixed bug #65715 (php5embed.lib isn't provided anymore). (Anatol).
index 10d5ed976dd82331c1240de3fa68d428f171c526..58aad8d6b66e446bd3fd471a3754d450d29e3520 100644 (file)
@@ -5590,14 +5590,19 @@ PHP_FUNCTION(substr_compare)
        int s1_len, s2_len;
        long offset, len=0;
        zend_bool cs=0;
+       uint cmp_len;
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl|lb", &s1, &s1_len, &s2, &s2_len, &offset, &len, &cs) == FAILURE) {
                RETURN_FALSE;
        }
 
-       if (ZEND_NUM_ARGS() >= 4 && len < 0) {
-               php_error_docref(NULL TSRMLS_CC, E_WARNING, "The length must be greater than or equal to zero");
-               RETURN_FALSE;
+       if (ZEND_NUM_ARGS() >= 4 && len <= 0) {
+               if (len == 0) {
+                       RETURN_LONG(0L);
+               } else {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "The length must be greater than or equal to zero");
+                       RETURN_FALSE;
+               }
        }
 
        if (offset < 0) {
@@ -5610,10 +5615,12 @@ PHP_FUNCTION(substr_compare)
                RETURN_FALSE;
        }
 
+       cmp_len = (uint) (len ? len : MAX(s2_len, (s1_len - offset)));
+
        if (!cs) {
-               RETURN_LONG(zend_binary_strncmp(s1 + offset, (s1_len - offset), s2, s2_len, (uint)len));
+               RETURN_LONG(zend_binary_strncmp(s1 + offset, (s1_len - offset), s2, s2_len, cmp_len));
        } else {
-               RETURN_LONG(zend_binary_strncasecmp_l(s1 + offset, (s1_len - offset), s2, s2_len, (uint)len));
+               RETURN_LONG(zend_binary_strncasecmp_l(s1 + offset, (s1_len - offset), s2, s2_len, cmp_len));
        }
 }
 /* }}} */
index 84777711e63e3a0e5cf606232aa268343eecc4f8..191a77e09807ce0249053f366468927b9b2d1af7 100644 (file)
@@ -3,6 +3,7 @@ substr_compare()
 --FILE--
 <?php
 
+var_dump(substr_compare("abcde", "df", -2));
 var_dump(substr_compare("abcde", "bc", 1, 2));
 var_dump(substr_compare("abcde", "bcg", 1, 2));
 var_dump(substr_compare("abcde", "BC", 1, 2, true));
@@ -20,6 +21,7 @@ var_dump(substr_compare("abcde", -1, 0, "str", new stdClass));
 echo "Done\n";
 ?>
 --EXPECTF--
+int(-1)
 int(0)
 int(0)
 int(0)