Skip to content

Commit 5a8c917

Browse files
committed
Fixed bug #54454 (substr_compare incorrectly reports equality in some cases)
1 parent 70075bc commit 5a8c917

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

ext/standard/string.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5252,10 +5252,6 @@ PHP_FUNCTION(substr_compare)
52525252
RETURN_FALSE;
52535253
}
52545254

5255-
if (len > s1_len - offset) {
5256-
len = s1_len - offset;
5257-
}
5258-
52595255
cmp_len = (uint) (len ? len : MAX(s2_len, (s1_len - offset)));
52605256

52615257
if (!cs) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
Bug #54454 (substr_compare incorrectly reports equality in some cases)
3+
--FILE--
4+
<?php
5+
var_dump(substr_compare('/', '/asd', 0, 4));
6+
?>
7+
--EXPECT--
8+
int(-3)

ext/standard/tests/strings/substr_compare.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ int(-1)
2727

2828
Warning: substr_compare(): The start position cannot exceed initial string length in %s on line %d
2929
bool(false)
30-
int(0)
30+
int(-1)
3131

3232
Warning: substr_compare() expects parameter 5 to be boolean, object given in %s on line %d
3333
bool(false)

0 commit comments

Comments
 (0)