com php-src: Fixed bug #74041: NEWS ext/standard/string.c ext/standard/tests/strings/bug74041.phpt

[email protected] (Nikita Popov)
Newsgroups php.cvs
Message-ID <[email protected]>
Commit:    8660e95b4c7a7a84278104bce4ad8270c1ac3464
Author:    Nikita Popov <[email protected]>         Fri, 3 Feb 2017 17:54:39 +0100
Parents:   611952cd9845bd0e046fc7bd24c17a7341b96f7d
Branches:  PHP-7.1 master

Link:       http://git.php.net/?p=php-src.git;a=commitdiff;h=8660e95b4c7a7a84278104bce4ad8270c1ac3464

Log:
Fixed bug #74041

Bugs:
https://bugs.php.net/74041

Changed paths:
  M  NEWS
  M  ext/standard/string.c
  A  ext/standard/tests/strings/bug74041.phpt


Diff:
diff --git a/NEWS b/NEWS
index 2cbbf75..d5ed848 100644
--- 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
 
diff --git a/ext/standard/string.c b/ext/standard/string.c
index debea2a..565caa3 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -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
index 0000000..598e46d
--- /dev/null
+++ b/ext/standard/tests/strings/bug74041.phpt
@@ -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)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.