Skip to content

Commit d7b5954

Browse files
committed
Fixed bug #77853
1 parent eea61cd commit d7b5954

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ PHP NEWS
3232
(Vlad Temian)
3333
. Fixed bug #77844 (Crash due to null pointer in parse_ini_string with
3434
INI_SCANNER_TYPED). (Nikita)
35+
. Fixed bug #77853 (Inconsistent substr_compare behaviour with empty
36+
haystack). (Nikita)
3537

3638
04 Apr 2019, PHP 7.2.17
3739

ext/standard/string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5739,7 +5739,7 @@ PHP_FUNCTION(substr_compare)
57395739
offset = (offset < 0) ? 0 : offset;
57405740
}
57415741

5742-
if ((size_t)offset >= ZSTR_LEN(s1)) {
5742+
if ((size_t)offset > ZSTR_LEN(s1)) {
57435743
php_error_docref(NULL, E_WARNING, "The start position cannot exceed initial string length");
57445744
RETURN_FALSE;
57455745
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Bug #77853: Inconsistent substr_compare behaviour with empty haystack
3+
--FILE--
4+
<?php
5+
6+
var_dump(substr_compare('', '', 0, 0));
7+
var_dump(substr_compare('', '', 0));
8+
9+
var_dump(substr_compare('abc', '', 3, 0));
10+
var_dump(substr_compare('abc', '', 3));
11+
12+
var_dump(substr_compare('abc', "\0", 3));
13+
14+
?>
15+
--EXPECT--
16+
int(0)
17+
int(0)
18+
int(0)
19+
int(0)
20+
int(-1)

ext/standard/tests/strings/substr_compare.phpt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ int(0)
2727
int(0)
2828
bool(true)
2929
bool(true)
30-
31-
Warning: substr_compare(): The start position cannot exceed initial string length in %s on line %d
32-
bool(false)
30+
int(-1)
3331
bool(true)
3432
int(0)
3533

0 commit comments

Comments
 (0)