fix leak, add test

This commit is contained in:
Antony Dovgal 2006-11-15 22:10:19 +00:00
parent 2eb308ff75
commit eca1911b72
2 changed files with 98 additions and 0 deletions

View File

@ -2656,6 +2656,7 @@ PHP_FUNCTION(array_pad)
num_pads = pad_size_abs - input_size;
if(num_pads > 1048576) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "You may only pad up to 1048576 elements at a time");
zval_dtor(return_value);
RETURN_FALSE;
}
pads = (zval ***)safe_emalloc(num_pads, sizeof(zval **), 0);

View File

@ -0,0 +1,97 @@
--TEST--
array_pad() tests
--FILE--
<?php
var_dump(array_pad());
var_dump(array_pad(array()));
var_dump(array_pad(array(), 1));
var_dump(array_pad(array(), 1, 0));
var_dump(array_pad(array(), 0, 0));
var_dump(array_pad(array(), -1, 0));
var_dump(array_pad(array("", -1, 2.0), 5, 0));
var_dump(array_pad(array("", -1, 2.0), 5, array()));
var_dump(array_pad(array("", -1, 2.0), 2, array()));
var_dump(array_pad(array("", -1, 2.0), -3, array()));
var_dump(array_pad(array("", -1, 2.0), -4, array()));
var_dump(array_pad(array("", -1, 2.0), 2000000, 0));
echo "Done\n";
?>
--EXPECTF--
Warning: Wrong parameter count for array_pad() in %s on line %d
NULL
Warning: Wrong parameter count for array_pad() in %s on line %d
NULL
Warning: Wrong parameter count for array_pad() in %s on line %d
NULL
array(1) {
[0]=>
int(0)
}
array(0) {
}
array(1) {
[0]=>
int(0)
}
array(5) {
[0]=>
string(0) ""
[1]=>
int(-1)
[2]=>
float(2)
[3]=>
int(0)
[4]=>
int(0)
}
array(5) {
[0]=>
string(0) ""
[1]=>
int(-1)
[2]=>
float(2)
[3]=>
array(0) {
}
[4]=>
array(0) {
}
}
array(3) {
[0]=>
string(0) ""
[1]=>
int(-1)
[2]=>
float(2)
}
array(3) {
[0]=>
string(0) ""
[1]=>
int(-1)
[2]=>
float(2)
}
array(4) {
[0]=>
array(0) {
}
[1]=>
string(0) ""
[2]=>
int(-1)
[3]=>
float(2)
}
Warning: array_pad(): You may only pad up to 1048576 elements at a time in %s on line %d
bool(false)
Done