com php-src: Make sure array_splice() always returns an array: ext/standard/array.c ext/standard/basic _functions.c
| From: | Nikita Popov | Date: | Wed, 05 Jun 2019 12:56:32 +0000 |
| Subject: | com php-src: Make sure array_splice() always returns an array: ext/standard/array.c ext/standard/basic _functions.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-106567@lists.php.net to get a copy of this message | ||
Commit: d3ed9d819297b6d9cf52f9d1c68ec64608d60aa7
Author: Nikita Popov <nikita.ppv@gmail.com> Wed, 5 Jun 2019 14:56:32 +0200
Parents: 7686b0b88906e2522300b9e631ddde2051de839f
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d3ed9d819297b6d9cf52f9d1c68ec64608d60aa7
Log:
Make sure array_splice() always returns an array
Return an array even if the return value isn't used. This allows us
to add the arginfo return type.
Changed paths:
M ext/standard/array.c
M ext/standard/basic_functions.c
Diff:
diff --git a/ext/standard/array.c b/ext/standard/array.c
index 6549062..53673c3 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -3382,7 +3382,7 @@ PHP_FUNCTION(array_unshift)
}
/* }}} */
-/* {{{ proto array|null array_splice(array input, int offset [, int length [, array replacement]])
+/* {{{ proto array array_splice(array input, int offset [, int length [, array replacement]])
Removes the elements designated by offset and length and replace them with supplied array */
PHP_FUNCTION(array_splice)
{
@@ -3434,6 +3434,9 @@ PHP_FUNCTION(array_splice)
/* Initialize return value */
array_init_size(return_value, size > 0 ? (uint32_t)size : 0);
rem_hash = Z_ARRVAL_P(return_value);
+ } else {
+ /* The return value will not be used, but make sure it still has the correct type. */
+ RETVAL_EMPTY_ARRAY();
}
/* Perform splice */
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index 5ffab56..ff5f11d 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -365,7 +365,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_array_unshift, 0, 1, IS_LONG, 0)
ZEND_ARG_VARIADIC_INFO(0, vars)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO_EX(arginfo_array_splice, 0, 0, 2)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_array_splice, 0, 2, IS_ARRAY, 0)
ZEND_ARG_INFO(1, arg) /* ARRAY_INFO(1, arg, 0) */
ZEND_ARG_INFO(0, offset)
ZEND_ARG_INFO(0, length)