diff options
author | Andrey Hristov <andrey@php.net> | 2014-04-10 16:49:13 +0300 |
---|---|---|
committer | Andrey Hristov <andrey@php.net> | 2014-04-10 16:49:13 +0300 |
commit | 090c3e87c0449e6eadf83815bb57c8a6eff4b56e (patch) | |
tree | 946fdc55ed17d2dc07a99b388565cc96197026dd /ext/standard/string.c | |
parent | 63791d055ad64762c3f63e08ca7ad8ba1f44e0ab (diff) | |
parent | 3204ad5858a5abc50b11b8527d22c82eb07a80cc (diff) | |
download | php-git-090c3e87c0449e6eadf83815bb57c8a6eff4b56e.tar.gz |
Merge branch 'PHP-5.6' of git.php.net:php-src into PHP-5.6
Conflicts:
ext/mysqli/tests/mysqli_begin_transaction.phpt
Diffstat (limited to 'ext/standard/string.c')
-rw-r--r-- | ext/standard/string.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/ext/standard/string.c b/ext/standard/string.c index eafa6cf2a0..9139906653 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -5585,14 +5585,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) { @@ -5605,10 +5610,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)); } } /* }}} */ |