mirror of
https://github.com/php/php-src.git
synced 2024-09-22 02:17:32 +00:00
Remove 'bogus' error condition in str_pad()
This commit is contained in:
parent
675e975185
commit
9d18f23c4c
@ -5697,11 +5697,6 @@ PHP_FUNCTION(str_pad)
|
||||
}
|
||||
|
||||
num_pad_chars = pad_length - ZSTR_LEN(input);
|
||||
if (num_pad_chars >= INT_MAX) {
|
||||
php_error_docref(NULL, E_WARNING, "Padding length is too long");
|
||||
return;
|
||||
}
|
||||
|
||||
result = zend_string_safe_alloc(1, ZSTR_LEN(input), num_pad_chars, 0);
|
||||
ZSTR_LEN(result) = 0;
|
||||
|
||||
|
36
ext/standard/tests/strings/str_pad_variation1.phpt
Normal file
36
ext/standard/tests/strings/str_pad_variation1.phpt
Normal file
@ -0,0 +1,36 @@
|
||||
--TEST--
|
||||
Test str_pad() function : usage variations - large values for '$pad_length' argument
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : string str_pad ( string $input , int $pad_length [, string $pad_string [, int $pad_type ]] )
|
||||
* Description: Pad a string to a certain length with another string
|
||||
* Source code: ext/standard/string.c
|
||||
*/
|
||||
|
||||
/* Test str_pad() function: with unexpected inputs for '$pad_length'
|
||||
* and expected type for '$input'
|
||||
*/
|
||||
|
||||
echo "*** Testing str_pad() function: with large value for for 'pad_length' argument ***\n";
|
||||
|
||||
//defining '$input' argument
|
||||
$input = "Test string";
|
||||
|
||||
$extra_large_pad_length = PHP_INT_MAX*5;
|
||||
try {
|
||||
var_dump( str_pad($input, $extra_large_pad_length) );
|
||||
} catch (\TypeError $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
|
||||
$php_int_max_pad_length = PHP_INT_MAX;
|
||||
var_dump( str_pad($input, $php_int_max_pad_length) );
|
||||
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
*** Testing str_pad() function: with large value for for 'pad_length' argument ***
|
||||
str_pad() expects parameter 2 to be int, float given
|
||||
|
||||
Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d
|
||||
|
@ -31,4 +31,4 @@ var_dump( str_pad($input, $pad_length) );
|
||||
--EXPECTF--
|
||||
*** Testing str_pad() function: with large value for for 'pad_length' argument ***
|
||||
|
||||
Fatal error: Allowed memory size of 134217728 bytes exhausted%s(tried to allocate %d bytes) in %s on line %d
|
||||
Fatal error: Allowed memory size of %d bytes exhausted%s(tried to allocate %d bytes) in %s on line %d
|
||||
|
Loading…
Reference in New Issue
Block a user