Skip to content

Commit 646f54b

Browse files
committed
ext/standard/array.c: use uint32_t instead of incorrect int type
Drive-by indentation fixes and bool usage
1 parent 1820c42 commit 646f54b

File tree

1 file changed

+48
-48
lines changed

1 file changed

+48
-48
lines changed

ext/standard/array.c

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -126,25 +126,25 @@ static zend_never_inline ZEND_COLD int stable_sort_fallback(Bucket *a, Bucket *b
126126

127127
static zend_always_inline int php_array_key_compare_unstable_i(Bucket *f, Bucket *s) /* {{{ */
128128
{
129-
zval first;
130-
zval second;
131-
132-
if (f->key == NULL && s->key == NULL) {
133-
return (zend_long)f->h > (zend_long)s->h ? 1 : -1;
134-
} else if (f->key && s->key) {
135-
return zendi_smart_strcmp(f->key, s->key);
136-
}
137-
if (f->key) {
138-
ZVAL_STR(&first, f->key);
139-
} else {
140-
ZVAL_LONG(&first, f->h);
141-
}
142-
if (s->key) {
143-
ZVAL_STR(&second, s->key);
144-
} else {
145-
ZVAL_LONG(&second, s->h);
146-
}
147-
return zend_compare(&first, &second);
129+
zval first;
130+
zval second;
131+
132+
if (f->key == NULL && s->key == NULL) {
133+
return (zend_long)f->h > (zend_long)s->h ? 1 : -1;
134+
} else if (f->key && s->key) {
135+
return zendi_smart_strcmp(f->key, s->key);
136+
}
137+
if (f->key) {
138+
ZVAL_STR(&first, f->key);
139+
} else {
140+
ZVAL_LONG(&first, f->h);
141+
}
142+
if (s->key) {
143+
ZVAL_STR(&second, s->key);
144+
} else {
145+
ZVAL_LONG(&second, s->h);
146+
}
147+
return zend_compare(&first, &second);
148148
}
149149
/* }}} */
150150

@@ -1210,7 +1210,7 @@ static int php_data_compare(const void *f, const void *s) /* {{{ */
12101210
Return the lowest value in an array or a series of arguments */
12111211
PHP_FUNCTION(min)
12121212
{
1213-
int argc;
1213+
uint32_t argc;
12141214
zval *args = NULL;
12151215

12161216
ZEND_PARSE_PARAMETERS_START(1, -1)
@@ -1234,7 +1234,7 @@ PHP_FUNCTION(min)
12341234
} else {
12351235
/* mixed min ( mixed $value1 , mixed $value2 [, mixed $value3... ] ) */
12361236
zval *min, result;
1237-
int i;
1237+
uint32_t i;
12381238

12391239
min = &args[0];
12401240

@@ -1257,7 +1257,7 @@ PHP_FUNCTION(min)
12571257
PHP_FUNCTION(max)
12581258
{
12591259
zval *args = NULL;
1260-
int argc;
1260+
uint32_t argc;
12611261

12621262
ZEND_PARSE_PARAMETERS_START(1, -1)
12631263
Z_PARAM_VARIADIC('+', args, argc)
@@ -1280,7 +1280,7 @@ PHP_FUNCTION(max)
12801280
} else {
12811281
/* mixed max ( mixed $value1 , mixed $value2 [, mixed $value3... ] ) */
12821282
zval *max, result;
1283-
int i;
1283+
uint32_t i;
12841284

12851285
max = &args[0];
12861286

@@ -2525,7 +2525,7 @@ static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_valu
25252525
php_error_docref(NULL, E_WARNING, "Undefined variable $%s", ZSTR_VAL(Z_STR_P(entry)));
25262526
}
25272527
} else if (Z_TYPE_P(entry) == IS_ARRAY) {
2528-
if (Z_REFCOUNTED_P(entry)) {
2528+
if (Z_REFCOUNTED_P(entry)) {
25292529
if (Z_IS_RECURSIVE_P(entry)) {
25302530
zend_throw_error(NULL, "Recursion detected");
25312531
return;
@@ -2535,7 +2535,7 @@ static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_valu
25352535
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(entry), value_ptr) {
25362536
php_compact_var(eg_active_symbol_table, return_value, value_ptr, pos);
25372537
} ZEND_HASH_FOREACH_END();
2538-
if (Z_REFCOUNTED_P(entry)) {
2538+
if (Z_REFCOUNTED_P(entry)) {
25392539
Z_UNPROTECT_RECURSION_P(entry);
25402540
}
25412541
} else {
@@ -3179,8 +3179,7 @@ PHP_FUNCTION(array_push)
31793179
zval *args, /* Function arguments array */
31803180
*stack, /* Input array */
31813181
new_var; /* Variable to be pushed */
3182-
int i, /* Loop counter */
3183-
argc; /* Number of function arguments */
3182+
uint32_t argc; /* Number of function arguments */
31843183

31853184

31863185
ZEND_PARSE_PARAMETERS_START(1, -1)
@@ -3189,7 +3188,7 @@ PHP_FUNCTION(array_push)
31893188
ZEND_PARSE_PARAMETERS_END();
31903189

31913190
/* For each subsequent argument, make it a reference, increase refcount, and add it to the end of the array */
3192-
for (i = 0; i < argc; i++) {
3191+
for (uint32_t i = 0; i < argc; i++) {
31933192
ZVAL_COPY(&new_var, &args[i]);
31943193

31953194
if (zend_hash_next_index_insert(Z_ARRVAL_P(stack), &new_var) == NULL) {
@@ -3387,8 +3386,7 @@ PHP_FUNCTION(array_unshift)
33873386
zval *args, /* Function arguments array */
33883387
*stack; /* Input stack */
33893388
HashTable new_hash; /* New hashtable for the stack */
3390-
int argc; /* Number of function arguments */
3391-
int i;
3389+
uint32_t argc; /* Number of function arguments */
33923390
zend_string *key;
33933391
zval *value;
33943392

@@ -3398,7 +3396,7 @@ PHP_FUNCTION(array_unshift)
33983396
ZEND_PARSE_PARAMETERS_END();
33993397

34003398
zend_hash_init(&new_hash, zend_hash_num_elements(Z_ARRVAL_P(stack)) + argc, NULL, ZVAL_PTR_DTOR, 0);
3401-
for (i = 0; i < argc; i++) {
3399+
for (uint32_t i = 0; i < argc; i++) {
34023400
Z_TRY_ADDREF(args[i]);
34033401
zend_hash_next_index_insert_new(&new_hash, &args[i]);
34043402
}
@@ -3818,8 +3816,8 @@ PHPAPI int php_array_replace_recursive(HashTable *dest, HashTable *src) /* {{{ *
38183816
dest_zval = dest_entry;
38193817
ZVAL_DEREF(dest_zval);
38203818
if (Z_IS_RECURSIVE_P(dest_zval) ||
3821-
Z_IS_RECURSIVE_P(src_zval) ||
3822-
(Z_ISREF_P(src_entry) && Z_ISREF_P(dest_entry) && Z_REF_P(src_entry) == Z_REF_P(dest_entry) && (Z_REFCOUNT_P(dest_entry) % 2))) {
3819+
Z_IS_RECURSIVE_P(src_zval) ||
3820+
(Z_ISREF_P(src_entry) && Z_ISREF_P(dest_entry) && Z_REF_P(src_entry) == Z_REF_P(dest_entry) && (Z_REFCOUNT_P(dest_entry) % 2))) {
38233821
zend_throw_error(NULL, "Recursion detected");
38243822
return 0;
38253823
}
@@ -3857,7 +3855,7 @@ static zend_always_inline void php_array_replace_wrapper(INTERNAL_FUNCTION_PARAM
38573855
{
38583856
zval *args = NULL;
38593857
zval *arg;
3860-
int argc, i;
3858+
uint32_t argc, i;
38613859
HashTable *dest;
38623860

38633861
ZEND_PARSE_PARAMETERS_START(1, -1)
@@ -3907,7 +3905,7 @@ static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMET
39073905
{
39083906
zval *args = NULL;
39093907
zval *arg;
3910-
int argc, i;
3908+
uint32_t argc, i;
39113909
zval *src_entry;
39123910
HashTable *src, *dest;
39133911
uint32_t count = 0;
@@ -4717,7 +4715,7 @@ static int zval_user_compare(zval *a, zval *b) /* {{{ */
47174715

47184716
static void php_array_intersect_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_type) /* {{{ */
47194717
{
4720-
int argc, i;
4718+
uint32_t argc, i;
47214719
zval *args;
47224720
int (*intersect_data_compare_func)(zval *, zval *) = NULL;
47234721
bool ok;
@@ -4799,7 +4797,8 @@ static void php_array_intersect(INTERNAL_FUNCTION_PARAMETERS, int behavior, int
47994797
{
48004798
zval *args = NULL;
48014799
HashTable *hash;
4802-
int arr_argc, i, c = 0;
4800+
uint32_t arr_argc, i;
4801+
int c = 0;
48034802
uint32_t idx;
48044803
Bucket **lists, *list, **ptrs, *p;
48054804
char *param_spec;
@@ -5117,7 +5116,7 @@ PHP_FUNCTION(array_uintersect_uassoc)
51175116

51185117
static void php_array_diff_key(INTERNAL_FUNCTION_PARAMETERS, int data_compare_type) /* {{{ */
51195118
{
5120-
int argc, i;
5119+
uint32_t argc, i;
51215120
zval *args;
51225121
int (*diff_data_compare_func)(zval *, zval *) = NULL;
51235122
bool ok;
@@ -5194,7 +5193,8 @@ static void php_array_diff(INTERNAL_FUNCTION_PARAMETERS, int behavior, int data_
51945193
{
51955194
zval *args = NULL;
51965195
HashTable *hash;
5197-
int arr_argc, i, c;
5196+
uint32_t arr_argc, i;
5197+
int c;
51985198
uint32_t idx;
51995199
Bucket **lists, *list, **ptrs, *p;
52005200
char *param_spec;
@@ -5460,7 +5460,7 @@ PHP_FUNCTION(array_diff_ukey)
54605460
PHP_FUNCTION(array_diff)
54615461
{
54625462
zval *args;
5463-
int argc, i;
5463+
uint32_t argc, i;
54645464
uint32_t num;
54655465
HashTable exclude;
54665466
zval *value;
@@ -5661,15 +5661,15 @@ PHP_FUNCTION(array_multisort)
56615661
zval* args;
56625662
zval** arrays;
56635663
Bucket** indirect;
5664-
uint32_t idx;
5664+
uint32_t idx;
56655665
HashTable* hash;
5666-
int argc;
5667-
int array_size;
5668-
int num_arrays = 0;
5666+
uint32_t argc;
5667+
uint32_t array_size;
5668+
uint32_t num_arrays = 0;
56695669
int parse_state[MULTISORT_LAST]; /* 0 - flag not allowed 1 - flag allowed */
56705670
int sort_order = PHP_SORT_ASC;
56715671
int sort_type = PHP_SORT_REGULAR;
5672-
int i, k, n;
5672+
uint32_t i, k, n;
56735673
bucket_compare_func_t *func;
56745674

56755675
ZEND_PARSE_PARAMETERS_START(1, -1)
@@ -5755,7 +5755,7 @@ PHP_FUNCTION(array_multisort)
57555755
/* Make sure the arrays are of the same size. */
57565756
array_size = zend_hash_num_elements(Z_ARRVAL_P(arrays[0]));
57575757
for (i = 1; i < num_arrays; i++) {
5758-
if (zend_hash_num_elements(Z_ARRVAL_P(arrays[i])) != (uint32_t)array_size) {
5758+
if (zend_hash_num_elements(Z_ARRVAL_P(arrays[i])) != array_size) {
57595759
zend_value_error("Array sizes are inconsistent");
57605760
MULTISORT_ABORT;
57615761
}
@@ -5815,14 +5815,14 @@ PHP_FUNCTION(array_multisort)
58155815
ZVAL_COPY_VALUE(&hash->arPacked[k], &indirect[k][i].val);
58165816
}
58175817
} else {
5818-
int repack = 1;
5818+
bool repack = true;
58195819

58205820
for (n = 0, k = 0; k < array_size; k++) {
58215821
hash->arData[k] = indirect[k][i];
58225822
if (hash->arData[k].key == NULL) {
58235823
hash->arData[k].h = n++;
58245824
} else {
5825-
repack = 0;
5825+
repack = false;
58265826
}
58275827
}
58285828
if (repack) {

0 commit comments

Comments
 (0)