summaryrefslogtreecommitdiff
path: root/ext/standard/array.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/array.c')
-rw-r--r--ext/standard/array.c44
1 files changed, 23 insertions, 21 deletions
diff --git a/ext/standard/array.c b/ext/standard/array.c
index 98a1c21b3e..57d0065b25 100644
--- a/ext/standard/array.c
+++ b/ext/standard/array.c
@@ -728,7 +728,7 @@ static int php_array_user_key_compare(const void *a, const void *b TSRMLS_DC) /*
zval_ptr_dtor(&args[0]);
zval_ptr_dtor(&args[1]);
- return result;
+ return result < 0 ? -1 : result > 0 ? 1 : 0;
}
/* }}} */
@@ -1301,9 +1301,10 @@ PHP_FUNCTION(array_search)
}
/* }}} */
-static int php_valid_var_name(char *var_name, int var_name_len) /* {{{ */
+static int php_valid_var_name(char *var_name, size_t var_name_len) /* {{{ */
{
- int i, ch;
+ size_t i;
+ int ch;
if (!var_name || !var_name_len) {
return 0;
@@ -1337,7 +1338,7 @@ static int php_valid_var_name(char *var_name, int var_name_len) /* {{{ */
}
/* }}} */
-PHPAPI int php_prefix_varname(zval *result, zval *prefix, char *var_name, int var_name_len, zend_bool add_underscore TSRMLS_DC) /* {{{ */
+PHPAPI int php_prefix_varname(zval *result, zval *prefix, char *var_name, size_t var_name_len, zend_bool add_underscore TSRMLS_DC) /* {{{ */
{
ZVAL_NEW_STR(result, zend_string_alloc(Z_STRLEN_P(prefix) + (add_underscore ? 1 : 0) + var_name_len, 0));
memcpy(Z_STRVAL_P(result), Z_STRVAL_P(prefix), Z_STRLEN_P(prefix));
@@ -1569,7 +1570,7 @@ PHP_FUNCTION(array_fill)
}
/* allocate an array for return */
- array_init_size(return_value, num);
+ array_init_size(return_value, (uint32_t)num);
if (num == 0) {
return;
@@ -1786,10 +1787,10 @@ err:
static void php_array_data_shuffle(zval *array TSRMLS_DC) /* {{{ */
{
- uint idx;
+ uint32_t idx, j, n_elems;
Bucket *p, temp;
HashTable *hash;
- int j, n_elems, rnd_idx, n_left;
+ zend_long rnd_idx, n_left;
n_elems = zend_hash_num_elements(Z_ARRVAL_P(array));
@@ -2222,7 +2223,7 @@ PHP_FUNCTION(array_splice)
/* Don't create the array of removed elements if it's not going
* to be used; e.g. only removing and/or replacing elements */
if (USED_RET()) {
- int size = length;
+ zend_long size = length;
/* Clamp the offset.. */
if (offset > num_in) {
@@ -2234,17 +2235,17 @@ PHP_FUNCTION(array_splice)
/* ..and the length */
if (length < 0) {
size = num_in - offset + length;
- } else if (((zend_ulong) offset + (zend_ulong) length) > (unsigned) num_in) {
+ } else if (((zend_ulong) offset + (zend_ulong) length) > (uint32_t) num_in) {
size = num_in - offset;
}
/* Initialize return value */
- array_init_size(return_value, size > 0 ? size : 0);
+ array_init_size(return_value, size > 0 ? (uint32_t)size : 0);
rem_hash = Z_ARRVAL_P(return_value);
}
/* Perform splice */
- new_hash = php_splice(Z_ARRVAL_P(array), offset, length, repl, repl_num, rem_hash);
+ new_hash = php_splice(Z_ARRVAL_P(array), (int)offset, (int)length, repl, (int)repl_num, rem_hash);
/* Replace input array's hashtable with the new one */
old_hash = *Z_ARRVAL_P(array);
@@ -2314,7 +2315,7 @@ PHP_FUNCTION(array_slice)
}
/* Initialize returned array */
- array_init_size(return_value, length > 0 ? length : 0);
+ array_init_size(return_value, length > 0 ? (uint32_t)length : 0);
if (length <= 0) {
return;
@@ -2897,9 +2898,9 @@ PHP_FUNCTION(array_pad)
/* Pad on the right or on the left */
if (pad_size > 0) {
- new_hash = php_splice(Z_ARRVAL_P(return_value), input_size, 0, pads, num_pads, NULL);
+ new_hash = php_splice(Z_ARRVAL_P(return_value), (int)input_size, 0, pads, (int)num_pads, NULL);
} else {
- new_hash = php_splice(Z_ARRVAL_P(return_value), 0, 0, pads, num_pads, NULL);
+ new_hash = php_splice(Z_ARRVAL_P(return_value), 0, 0, pads, (int)num_pads, NULL);
}
/* Copy the result hash into return value */
@@ -3971,22 +3972,23 @@ PHPAPI int php_multisort_compare(const void *a, const void *b TSRMLS_DC) /* {{{
Bucket *ab = *(Bucket **)a;
Bucket *bb = *(Bucket **)b;
int r;
- int result = 0;
+ zend_long result;
zval temp;
r = 0;
do {
+
php_set_compare_func(ARRAYG(multisort_flags)[MULTISORT_TYPE][r] TSRMLS_CC);
ARRAYG(compare_func)(&temp, &ab[r].val, &bb[r].val TSRMLS_CC);
result = ARRAYG(multisort_flags)[MULTISORT_ORDER][r] * Z_LVAL(temp);
if (result != 0) {
- return result;
+ return result > 0 ? 1 : -1;
}
r++;
} while (Z_TYPE(ab[r].val) != IS_UNDEF);
- return result;
+ return 0;
}
/* }}} */
@@ -4077,7 +4079,7 @@ PHP_FUNCTION(array_multisort)
/* flag allowed here */
if (parse_state[MULTISORT_TYPE] == 1) {
/* Save the flag and make sure then next arg is not the current flag. */
- sort_type = Z_LVAL(args[i]);
+ sort_type = (int)Z_LVAL(args[i]);
parse_state[MULTISORT_TYPE] = 0;
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument #%d is expected to be an array or sorting flag that has not already been specified", i + 1);
@@ -4205,7 +4207,7 @@ PHP_FUNCTION(array_rand)
/* Make the return value an array only if we need to pass back more than one result. */
if (num_req > 1) {
- array_init_size(return_value, num_req);
+ array_init_size(return_value, (uint32_t)num_req);
}
/* We can't use zend_hash_index_find() because the array may have string keys or gaps. */
@@ -4690,14 +4692,14 @@ PHP_FUNCTION(array_chunk)
size = num_in > 0 ? num_in : 1;
}
- array_init_size(return_value, ((num_in - 1) / size) + 1);
+ array_init_size(return_value, (uint32_t)(((num_in - 1) / size) + 1));
ZVAL_UNDEF(&chunk);
ZEND_HASH_FOREACH_KEY_VAL(Z_ARRVAL_P(input), num_key, str_key, entry) {
/* If new chunk, create and initialize it. */
if (Z_TYPE(chunk) == IS_UNDEF) {
- array_init_size(&chunk, size);
+ array_init_size(&chunk, (uint32_t)size);
}
/* Add entry to the chunk, preserving keys if necessary. */