Skip to content

Commit 59636f5

Browse files
committed
Zend: use type uint32_t for default_properties_count CE field
1 parent 5b754d6 commit 59636f5

File tree

9 files changed

+28
-39
lines changed

9 files changed

+28
-39
lines changed

Zend/zend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ struct _zend_class_entry {
156156
uint32_t ce_flags;
157157
uint32_t ce_flags2;
158158

159-
int default_properties_count;
159+
uint32_t default_properties_count;
160160
int default_static_members_count;
161161
zval *default_properties_table;
162162
zval *default_static_members_table;

Zend/zend_lazy_objects.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,13 @@ ZEND_API zend_object *zend_object_make_lazy(zend_object *obj,
269269
obj = zend_objects_new(reflection_ce);
270270

271271
/* Iterate in reverse to avoid overriding Z_PROP_FLAG_P() of child props with added hooks (GH-17870). */
272-
for (int i = obj->ce->default_properties_count - 1; i >= 0; i--) {
273-
zval *p = &obj->properties_table[i];
272+
for (uint32_t i = obj->ce->default_properties_count - 1; i > 0; i--) {
273+
uint32_t index = i - 1;
274+
zval *p = &obj->properties_table[index];
274275
ZVAL_UNDEF(p);
275276
Z_PROP_FLAG_P(p) = 0;
276277

277-
zend_property_info *prop_info = obj->ce->properties_info_table[i];
278+
zend_property_info *prop_info = obj->ce->properties_info_table[index];
278279
if (prop_info) {
279280
zval *p = &obj->properties_table[OBJ_PROP_TO_NUM(prop_info->offset)];
280281
Z_PROP_FLAG_P(p) = IS_PROP_UNINIT | IS_PROP_LAZY;
@@ -326,7 +327,7 @@ ZEND_API zend_object *zend_object_make_lazy(zend_object *obj,
326327
}
327328

328329
/* unset() declared properties */
329-
for (int i = 0; i < reflection_ce->default_properties_count; i++) {
330+
for (uint32_t i = 0; i < reflection_ce->default_properties_count; i++) {
330331
zend_property_info *prop_info = obj->ce->properties_info_table[i];
331332
if (EXPECTED(prop_info)) {
332333
zval *p = &obj->properties_table[OBJ_PROP_TO_NUM(prop_info->offset)];
@@ -390,7 +391,7 @@ ZEND_API zend_object *zend_lazy_object_mark_as_initialized(zend_object *obj)
390391

391392
OBJ_EXTRA_FLAGS(obj) &= ~(IS_OBJ_LAZY_UNINITIALIZED|IS_OBJ_LAZY_PROXY);
392393

393-
for (int i = 0; i < ce->default_properties_count; i++) {
394+
for (uint32_t i = 0; i < ce->default_properties_count; i++) {
394395
if (Z_PROP_FLAG_P(&properties_table[i]) & IS_PROP_LAZY) {
395396
ZVAL_COPY_PROP(&properties_table[i], &default_properties_table[i]);
396397
}
@@ -410,7 +411,7 @@ static void zend_lazy_object_revert_init(zend_object *obj, zval *properties_tabl
410411
ZEND_ASSERT(properties_table_snapshot);
411412
zval *properties_table = obj->properties_table;
412413

413-
for (int i = 0; i < ce->default_properties_count; i++) {
414+
for (uint32_t i = 0; i < ce->default_properties_count; i++) {
414415
zend_property_info *prop_info = ce->properties_info_table[i];
415416
if (!prop_info) {
416417
continue;
@@ -532,7 +533,7 @@ static zend_object *zend_lazy_object_init_proxy(zend_object *obj)
532533
zend_object_dtor_dynamic_properties(obj);
533534
obj->properties = NULL;
534535

535-
for (int i = 0; i < Z_OBJ(retval)->ce->default_properties_count; i++) {
536+
for (uint32_t i = 0; i < Z_OBJ(retval)->ce->default_properties_count; i++) {
536537
zend_property_info *prop_info = Z_OBJ(retval)->ce->properties_info_table[i];
537538
if (EXPECTED(prop_info)) {
538539
zval *prop = &obj->properties_table[OBJ_PROP_TO_NUM(prop_info->offset)];
@@ -608,7 +609,7 @@ ZEND_API zend_object *zend_lazy_object_init(zend_object *obj)
608609
zval *properties_table = obj->properties_table;
609610
properties_table_snapshot = emalloc(sizeof(*properties_table_snapshot) * ce->default_properties_count);
610611

611-
for (int i = 0; i < ce->default_properties_count; i++) {
612+
for (uint32_t i = 0; i < ce->default_properties_count; i++) {
612613
ZVAL_COPY_PROP(&properties_table_snapshot[i], &properties_table[i]);
613614
if (Z_PROP_FLAG_P(&properties_table[i]) & IS_PROP_LAZY) {
614615
ZVAL_COPY_PROP(&properties_table[i], &default_properties_table[i]);
@@ -640,7 +641,7 @@ ZEND_API zend_object *zend_lazy_object_init(zend_object *obj)
640641
}
641642

642643
if (properties_table_snapshot) {
643-
for (int i = 0; i < obj->ce->default_properties_count; i++) {
644+
for (uint32_t i = 0; i < obj->ce->default_properties_count; i++) {
644645
zval *p = &properties_table_snapshot[i];
645646
/* Use zval_ptr_dtor directly here (not zend_object_dtor_property),
646647
* as any reference type_source will have already been deleted in
@@ -681,7 +682,7 @@ void zend_lazy_object_realize(zend_object *obj)
681682
zend_lazy_object_del_info(obj);
682683

683684
#if ZEND_DEBUG
684-
for (int i = 0; i < obj->ce->default_properties_count; i++) {
685+
for (uint32_t i = 0; i < obj->ce->default_properties_count; i++) {
685686
ZEND_ASSERT(!(Z_PROP_FLAG_P(&obj->properties_table[i]) & IS_PROP_LAZY));
686687
}
687688
#endif
@@ -732,12 +733,13 @@ zend_object *zend_lazy_object_clone(zend_object *old_obj)
732733
zend_object *new_proxy = zend_objects_new(ce);
733734

734735
/* Iterate in reverse to avoid overriding Z_PROP_FLAG_P() of child props with added hooks (GH-17870). */
735-
for (int i = ce->default_properties_count - 1; i >= 0; i--) {
736-
zval *p = &new_proxy->properties_table[i];
736+
for (uint32_t i = ce->default_properties_count; i > 0; i--) {
737+
uint32_t index = i - 1;
738+
zval *p = &new_proxy->properties_table[index];
737739
ZVAL_UNDEF(p);
738740
Z_PROP_FLAG_P(p) = 0;
739741

740-
zend_property_info *prop_info = ce->properties_info_table[i];
742+
zend_property_info *prop_info = ce->properties_info_table[index];
741743
if (prop_info) {
742744
zval *p = &new_proxy->properties_table[OBJ_PROP_TO_NUM(prop_info->offset)];
743745
Z_PROP_FLAG_P(p) = IS_PROP_UNINIT | IS_PROP_LAZY;

Zend/zend_object_handlers.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,11 @@ ZEND_API HashTable *rebuild_object_properties_internal(zend_object *zobj) /* {{{
7777
if (!zobj->properties) {
7878
zend_property_info *prop_info;
7979
zend_class_entry *ce = zobj->ce;
80-
int i;
8180

8281
zobj->properties = zend_new_array(ce->default_properties_count);
8382
if (ce->default_properties_count) {
8483
zend_hash_real_init_mixed(zobj->properties);
85-
for (i = 0; i < ce->default_properties_count; i++) {
84+
for (uint32_t i = 0; i < ce->default_properties_count; i++) {
8685
prop_info = ce->properties_info_table[i];
8786

8887
if (!prop_info) {
@@ -110,14 +109,13 @@ ZEND_API HashTable *zend_std_build_object_properties_array(zend_object *zobj) /*
110109
zend_class_entry *ce = zobj->ce;
111110
HashTable *ht;
112111
zval* prop;
113-
int i;
114112

115113
ZEND_ASSERT(!(zend_object_is_lazy_proxy(zobj) && zend_lazy_object_initialized(zobj)));
116114
ZEND_ASSERT(!zobj->properties);
117115
ht = zend_new_array(ce->default_properties_count);
118116
if (ce->default_properties_count) {
119117
zend_hash_real_init_mixed(ht);
120-
for (i = 0; i < ce->default_properties_count; i++) {
118+
for (uint32_t i = 0; i < ce->default_properties_count; i++) {
121119
prop_info = ce->properties_info_table[i];
122120

123121
if (!prop_info) {
@@ -2191,7 +2189,6 @@ ZEND_API int zend_std_compare_objects(zval *o1, zval *o2) /* {{{ */
21912189
if (!zobj1->properties && !zobj2->properties
21922190
&& !zend_object_is_lazy(zobj1) && !zend_object_is_lazy(zobj2)) {
21932191
zend_property_info *info;
2194-
int i;
21952192

21962193
if (!zobj1->ce->default_properties_count) {
21972194
return 0;
@@ -2212,7 +2209,7 @@ ZEND_API int zend_std_compare_objects(zval *o1, zval *o2) /* {{{ */
22122209
GC_ADDREF(zobj2);
22132210
int ret;
22142211

2215-
for (i = 0; i < zobj1->ce->default_properties_count; i++) {
2212+
for (uint32_t i = 0; i < zobj1->ce->default_properties_count; i++) {
22162213
zval *p1, *p2;
22172214

22182215
info = zobj1->ce->properties_info_table[i];

ext/json/json_encoder.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ static zend_result php_json_encode_array(smart_str *buf, zval *val, int options,
147147

148148
++encoder->depth;
149149

150-
for (int i = 0; i < ce->default_properties_count; i++) {
150+
for (uint32_t i = 0; i < ce->default_properties_count; i++) {
151151
zend_property_info *prop_info = ce->properties_info_table[i];
152152
if (!prop_info) {
153153
continue;

ext/opcache/ZendAccelerator.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3903,10 +3903,9 @@ static bool preload_try_resolve_constants(zend_class_entry *ce)
39033903
ce->ce_flags &= ~ZEND_ACC_HAS_AST_CONSTANTS;
39043904
}
39053905
if (ce->default_properties_count) {
3906-
uint32_t i;
39073906
bool resolved = true;
39083907

3909-
for (i = 0; i < ce->default_properties_count; i++) {
3908+
for (uint32_t i = 0; i < ce->default_properties_count; i++) {
39103909
zend_property_info *prop = ce->properties_info_table[i];
39113910
if (!prop) {
39123911
continue;

ext/opcache/zend_file_cache.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,14 +813,13 @@ static void zend_file_cache_serialize_class(zval *zv,
813813
zend_file_cache_serialize_hash(&ce->properties_info, script, info, buf, zend_file_cache_serialize_prop_info);
814814

815815
if (ce->properties_info_table) {
816-
uint32_t i;
817816
zend_property_info **table;
818817

819818
SERIALIZE_PTR(ce->properties_info_table);
820819
table = ce->properties_info_table;
821820
UNSERIALIZE_PTR(table);
822821

823-
for (i = 0; i < ce->default_properties_count; i++) {
822+
for (uint32_t i = 0; i < ce->default_properties_count; i++) {
824823
SERIALIZE_PTR(table[i]);
825824
}
826825
}
@@ -1698,10 +1697,9 @@ static void zend_file_cache_unserialize_class(zval *zv,
16981697
script, buf, zend_file_cache_unserialize_prop_info, NULL);
16991698

17001699
if (ce->properties_info_table) {
1701-
uint32_t i;
17021700
UNSERIALIZE_PTR(ce->properties_info_table);
17031701

1704-
for (i = 0; i < ce->default_properties_count; i++) {
1702+
for (uint32_t i = 0; i < ce->default_properties_count; i++) {
17051703
UNSERIALIZE_PTR(ce->properties_info_table[i]);
17061704
}
17071705
}

ext/opcache/zend_persist.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -959,10 +959,8 @@ zend_class_entry *zend_persist_class_entry(zend_class_entry *orig_ce)
959959
} ZEND_HASH_FOREACH_END();
960960
HT_FLAGS(&ce->function_table) &= (HASH_FLAG_UNINITIALIZED | HASH_FLAG_STATIC_KEYS);
961961
if (ce->default_properties_table) {
962-
int i;
963-
964962
ce->default_properties_table = zend_shared_memdup_free(ce->default_properties_table, sizeof(zval) * ce->default_properties_count);
965-
for (i = 0; i < ce->default_properties_count; i++) {
963+
for (uint32_t i = 0; i < ce->default_properties_count; i++) {
966964
zend_persist_zval(&ce->default_properties_table[i]);
967965
}
968966
}
@@ -1015,14 +1013,12 @@ zend_class_entry *zend_persist_class_entry(zend_class_entry *orig_ce)
10151013
HT_FLAGS(&ce->properties_info) &= (HASH_FLAG_UNINITIALIZED | HASH_FLAG_STATIC_KEYS);
10161014

10171015
if (ce->properties_info_table) {
1018-
int i;
1019-
10201016
size_t size = sizeof(zend_property_info *) * ce->default_properties_count;
10211017
ZEND_ASSERT(ce->ce_flags & ZEND_ACC_LINKED);
10221018
ce->properties_info_table = zend_shared_memdup(
10231019
ce->properties_info_table, size);
10241020

1025-
for (i = 0; i < ce->default_properties_count; i++) {
1021+
for (uint32_t i = 0; i < ce->default_properties_count; i++) {
10261022
if (ce->properties_info_table[i]) {
10271023
zend_property_info *prop_info = zend_shared_alloc_get_xlat_entry(
10281024
ce->properties_info_table[i]);

ext/opcache/zend_persist_calc.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,10 +471,8 @@ void zend_persist_class_entry_calc(zend_class_entry *ce)
471471
zend_persist_class_method_calc(Z_PTR(p->val));
472472
} ZEND_HASH_FOREACH_END();
473473
if (ce->default_properties_table) {
474-
int i;
475-
476474
ADD_SIZE(sizeof(zval) * ce->default_properties_count);
477-
for (i = 0; i < ce->default_properties_count; i++) {
475+
for (uint32_t i = 0; i < ce->default_properties_count; i++) {
478476
zend_persist_zval_calc(&ce->default_properties_table[i]);
479477
}
480478
}

ext/standard/var.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,10 +1243,9 @@ static void php_var_serialize_intern(smart_str *buf, zval *struc, php_serialize_
12431243
zend_class_entry *ce = obj->ce;
12441244
zend_property_info *prop_info;
12451245
zval *prop;
1246-
int i;
12471246

12481247
count = ce->default_properties_count;
1249-
for (i = 0; i < ce->default_properties_count; i++) {
1248+
for (uint32_t i = 0; i < ce->default_properties_count; i++) {
12501249
prop_info = ce->properties_info_table[i];
12511250
if (!prop_info) {
12521251
count--;
@@ -1261,7 +1260,7 @@ static void php_var_serialize_intern(smart_str *buf, zval *struc, php_serialize_
12611260
if (count) {
12621261
smart_str_append_unsigned(buf, count);
12631262
smart_str_appendl(buf, ":{", 2);
1264-
for (i = 0; i < ce->default_properties_count; i++) {
1263+
for (uint32_t i = 0; i < ce->default_properties_count; i++) {
12651264
prop_info = ce->properties_info_table[i];
12661265
if (!prop_info) {
12671266
continue;

0 commit comments

Comments
 (0)