summaryrefslogtreecommitdiff
path: root/ext/standard/string.c
diff options
context:
space:
mode:
authorTjerk Meesters <datibbaw@php.net>2014-04-09 07:33:55 +0800
committerTjerk Meesters <datibbaw@php.net>2014-04-09 07:33:55 +0800
commit032921d80cd97d1d8a696348ce6bb0fd17e597e8 (patch)
treea1c7f96e059f6b9618fb1303dd1a9e6e476af30d /ext/standard/string.c
parent4141ceb7951eb5b003e8616774d39e665b9914c7 (diff)
downloadphp-git-032921d80cd97d1d8a696348ce6bb0fd17e597e8.tar.gz
Fixed bug 67043
Diffstat (limited to 'ext/standard/string.c')
-rw-r--r--ext/standard/string.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/ext/standard/string.c b/ext/standard/string.c
index 10d5ed976d..58aad8d6b6 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -5590,14 +5590,19 @@ PHP_FUNCTION(substr_compare)
int s1_len, s2_len;
long offset, len=0;
zend_bool cs=0;
+ uint cmp_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ssl|lb", &s1, &s1_len, &s2, &s2_len, &offset, &len, &cs) == FAILURE) {
RETURN_FALSE;
}
- if (ZEND_NUM_ARGS() >= 4 && len < 0) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "The length must be greater than or equal to zero");
- RETURN_FALSE;
+ if (ZEND_NUM_ARGS() >= 4 && len <= 0) {
+ if (len == 0) {
+ RETURN_LONG(0L);
+ } else {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "The length must be greater than or equal to zero");
+ RETURN_FALSE;
+ }
}
if (offset < 0) {
@@ -5610,10 +5615,12 @@ PHP_FUNCTION(substr_compare)
RETURN_FALSE;
}
+ cmp_len = (uint) (len ? len : MAX(s2_len, (s1_len - offset)));
+
if (!cs) {
- RETURN_LONG(zend_binary_strncmp(s1 + offset, (s1_len - offset), s2, s2_len, (uint)len));
+ RETURN_LONG(zend_binary_strncmp(s1 + offset, (s1_len - offset), s2, s2_len, cmp_len));
} else {
- RETURN_LONG(zend_binary_strncasecmp_l(s1 + offset, (s1_len - offset), s2, s2_len, (uint)len));
+ RETURN_LONG(zend_binary_strncasecmp_l(s1 + offset, (s1_len - offset), s2, s2_len, cmp_len));
}
}
/* }}} */