From: Antony Dovgal Date: Fri, 9 Mar 2007 10:04:59 +0000 (+0000) Subject: fix substr() X-Git-Tag: php-5.2.2RC1~180 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=982de65f6e761fe28966f4261bb0176d90bddc46;p=php fix substr() it's perfectly legal to do substr("str", 0, 1000000); --- diff --git a/ext/standard/string.c b/ext/standard/string.c index d05a9bfed2..7f7eb85d7f 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -2063,7 +2063,7 @@ PHP_FUNCTION(substr) if (argc > 2) { convert_to_long_ex(len); l = Z_LVAL_PP(len); - if (l > Z_STRLEN_PP(str) || (l < 0 && -l > Z_STRLEN_PP(str))) { + if ((l < 0 && -l > Z_STRLEN_PP(str))) { RETURN_FALSE; } } else { diff --git a/ext/standard/tests/strings/bug40754.phpt b/ext/standard/tests/strings/bug40754.phpt index f722ecc784..23a459317b 100644 --- a/ext/standard/tests/strings/bug40754.phpt +++ b/ext/standard/tests/strings/bug40754.phpt @@ -27,36 +27,36 @@ var_dump(substr("abcde", $v, $v)); ?> --EXPECTF-- -bool(false) +string(4) "bcde" bool(false) bool(false) bool(false) -Warning: substr_count(): Offset value 2147483647 exceeds string length. in %s/bug40754.php on line %d +Warning: substr_count(): Offset value 2147483647 exceeds string length. in %s on line %d bool(false) -Warning: substr_compare(): The start position cannot exceed initial string length in %s/bug40754.php on line %d +Warning: substr_compare(): The start position cannot exceed initial string length in %s on line %d bool(false) -Warning: stripos(): Offset not contained in string. in %s/bug40754.php on line %d +Warning: stripos(): Offset not contained in string. in %s on line %d bool(false) -Warning: substr_count(): Offset value 2147483647 exceeds string length. in %s/bug40754.php on line %d +Warning: substr_count(): Offset value 2147483647 exceeds string length. in %s on line %d bool(false) -Warning: substr_count(): Length value 2147483647 exceeds string length. in %s/bug40754.php on line %d +Warning: substr_count(): Length value 2147483647 exceeds string length. in %s on line %d bool(false) -Warning: strpos(): Offset not contained in string. in %s/bug40754.php on line %d +Warning: strpos(): Offset not contained in string. in %s on line %d bool(false) -Warning: stripos(): Offset not contained in string. in %s/bug40754.php on line %d +Warning: stripos(): Offset not contained in string. in %s on line %d bool(false) -Notice: strrpos(): Offset is greater than the length of haystack string in %s/bug40754.php on line %d +Notice: strrpos(): Offset is greater than the length of haystack string in %s on line %d bool(false) -Notice: strripos(): Offset is greater than the length of haystack string in %s/bug40754.php on line %d +Notice: strripos(): Offset is greater than the length of haystack string in %s on line %d bool(false) int(2) string(8) "abcdeabc"