]> granicus.if.org Git - php/commitdiff
fix substr()
authorAntony Dovgal <tony2001@php.net>
Fri, 9 Mar 2007 10:04:59 +0000 (10:04 +0000)
committerAntony Dovgal <tony2001@php.net>
Fri, 9 Mar 2007 10:04:59 +0000 (10:04 +0000)
it's perfectly legal to do substr("str", 0, 1000000);

ext/standard/string.c
ext/standard/tests/strings/bug40754.phpt

index d05a9bfed2084da74f5471cb3b73c4a7d69c97de..7f7eb85d7fef7c7b1537f459c2d6c695d5de1f69 100644 (file)
@@ -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 {
index f722ecc784f07dd1d6b5d19aa83c2d297d0eb2ed..23a459317b474e37de0651d3e3cd31cb1eacd459 100644 (file)
@@ -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"