Skip to content

Commit 419d98b

Browse files
committed
Merge branch 'PHP-5.6'
2 parents d349971 + 2cdf38b commit 419d98b

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

ext/standard/string.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5585,14 +5585,19 @@ PHP_FUNCTION(substr_compare)
55855585
int s1_len, s2_len;
55865586
long offset, len=0;
55875587
zend_bool cs=0;
5588+
uint cmp_len;
55885589

55895590
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl|lb", &s1, &s1_len, &s2, &s2_len, &offset, &len, &cs) == FAILURE) {
55905591
RETURN_FALSE;
55915592
}
55925593

5593-
if (ZEND_NUM_ARGS() >= 4 && len < 0) {
5594-
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The length must be greater than or equal to zero");
5595-
RETURN_FALSE;
5594+
if (ZEND_NUM_ARGS() >= 4 && len <= 0) {
5595+
if (len == 0) {
5596+
RETURN_LONG(0L);
5597+
} else {
5598+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The length must be greater than or equal to zero");
5599+
RETURN_FALSE;
5600+
}
55965601
}
55975602

55985603
if (offset < 0) {
@@ -5605,10 +5610,12 @@ PHP_FUNCTION(substr_compare)
56055610
RETURN_FALSE;
56065611
}
56075612

5613+
cmp_len = (uint) (len ? len : MAX(s2_len, (s1_len - offset)));
5614+
56085615
if (!cs) {
5609-
RETURN_LONG(zend_binary_strncmp(s1 + offset, (s1_len - offset), s2, s2_len, (uint)len));
5616+
RETURN_LONG(zend_binary_strncmp(s1 + offset, (s1_len - offset), s2, s2_len, cmp_len));
56105617
} else {
5611-
RETURN_LONG(zend_binary_strncasecmp_l(s1 + offset, (s1_len - offset), s2, s2_len, (uint)len));
5618+
RETURN_LONG(zend_binary_strncasecmp_l(s1 + offset, (s1_len - offset), s2, s2_len, cmp_len));
56125619
}
56135620
}
56145621
/* }}} */

ext/standard/tests/strings/substr_compare.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ substr_compare()
33
--FILE--
44
<?php
55

6+
var_dump(substr_compare("abcde", "df", -2));
67
var_dump(substr_compare("abcde", "bc", 1, 2));
78
var_dump(substr_compare("abcde", "bcg", 1, 2));
89
var_dump(substr_compare("abcde", "BC", 1, 2, true));
@@ -20,6 +21,7 @@ var_dump(substr_compare("abcde", -1, 0, "str", new stdClass));
2021
echo "Done\n";
2122
?>
2223
--EXPECTF--
24+
int(-1)
2325
int(0)
2426
int(0)
2527
int(0)

0 commit comments

Comments
 (0)