]> granicus.if.org Git - php/commitdiff
Fixed bug #74041
authorNikita Popov <nikita.ppv@gmail.com>
Fri, 3 Feb 2017 16:54:39 +0000 (17:54 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Fri, 3 Feb 2017 16:54:39 +0000 (17:54 +0100)
NEWS
ext/standard/string.c
ext/standard/tests/strings/bug74041.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 2cbbf752d84a72228a32640387e3bfcce85db847..d5ed848b368fd7874f5be4db6406b62e04fba7b2 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,7 @@ PHP                                                                        NEWS
 - Standard:
   . Fixed bug #74005 (mail.add_x_header causes RFC-breaking lone line feed).
     (Anatol)
+  . Fixed bug #74041 (substr_count with length=0 broken). (Nikita)
 
 16 Feb 2017, PHP 7.1.2
 
index debea2a0a8f5a3964e0a1d091d5d4a6f9570dc2a..565caa3bfb4ddcec7676d295eeaa4802bfd4382c 100644 (file)
@@ -5219,10 +5219,10 @@ PHP_FUNCTION(substr_count)
 
        if (ac == 4) {
 
-               if (length <= 0) {
+               if (length < 0) {
                        length += (haystack_len - offset);
                }
-               if ((length <= 0) || ((size_t)length > (haystack_len - offset))) {
+               if (length < 0 || ((size_t)length > (haystack_len - offset))) {
                        php_error_docref(NULL, E_WARNING, "Invalid length value");
                        RETURN_FALSE;
                }
diff --git a/ext/standard/tests/strings/bug74041.phpt b/ext/standard/tests/strings/bug74041.phpt
new file mode 100644 (file)
index 0000000..598e46d
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Bug #74041: substr_count with length=0 broken
+--FILE--
+<?php
+
+var_dump(substr_count("aaa", "a", 0, 0));
+var_dump(substr_count("", "a", 0, 0));
+
+?>
+--EXPECT--
+int(0)
+int(0)