Skip to content

Commit 4cc2924

Browse files
Reflection: integer types cleanup
Use `uint32_t` for values that are really `uint32_t`, like constant module numbers and the result from `zend_hash_num_elements()`. Use `uint32_t` for counting up, when values should never be negative. Adjust format specifiers to use `%u` rather than `%d` for the unsigned values.
1 parent 46a35ff commit 4cc2924

1 file changed

Lines changed: 26 additions & 26 deletions

File tree

ext/reflection/php_reflection.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const
375375

376376
/* The information where a class is declared is only available for user classes */
377377
if (ce->type == ZEND_USER_CLASS) {
378-
smart_str_append_printf(str, "%s @@ %s %d-%d\n", indent, ZSTR_VAL(ce->info.user.filename),
378+
smart_str_append_printf(str, "%s @@ %s %u-%u\n", indent, ZSTR_VAL(ce->info.user.filename),
379379
ce->info.user.line_start, ce->info.user.line_end);
380380
}
381381

@@ -410,12 +410,12 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const
410410
// Enum cases go first, but the heading is only shown if there are any
411411
if (enum_case_count) {
412412
smart_str_appendc(str, '\n');
413-
smart_str_append_printf(str, "%s - Enum cases [%d] {\n", indent, enum_case_count);
413+
smart_str_append_printf(str, "%s - Enum cases [%u] {\n", indent, enum_case_count);
414414
smart_str_append_smart_str(str, &enum_case_str);
415415
smart_str_append_printf(str, "%s }\n", indent);
416416
}
417417
smart_str_appendc(str, '\n');
418-
smart_str_append_printf(str, "%s - Constants [%d] {\n", indent, constant_count);
418+
smart_str_append_printf(str, "%s - Constants [%u] {\n", indent, constant_count);
419419
smart_str_append_smart_str(str, &constant_str);
420420
smart_str_append_printf(str, "%s }\n", indent);
421421

@@ -424,9 +424,9 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const
424424

425425
/* Static properties */
426426
/* counting static properties */
427-
int count = zend_hash_num_elements(&ce->properties_info);
428-
int count_static_props = 0;
429-
int count_shadow_props = 0;
427+
uint32_t count = zend_hash_num_elements(&ce->properties_info);
428+
uint32_t count_static_props = 0;
429+
uint32_t count_shadow_props = 0;
430430
if (count > 0) {
431431
ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, zend_property_info *prop) {
432432
if ((prop->flags & ZEND_ACC_PRIVATE) && prop->ce != ce) {
@@ -438,7 +438,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const
438438
}
439439

440440
/* static properties */
441-
smart_str_append_printf(str, "\n%s - Static properties [%d] {\n", indent, count_static_props);
441+
smart_str_append_printf(str, "\n%s - Static properties [%u] {\n", indent, count_static_props);
442442
if (count_static_props > 0) {
443443
ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, zend_property_info *prop) {
444444
if ((prop->flags & ZEND_ACC_STATIC) && (!(prop->flags & ZEND_ACC_PRIVATE) || prop->ce == ce)) {
@@ -451,7 +451,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const
451451
/* Static methods */
452452
/* counting static methods */
453453
count = zend_hash_num_elements(&ce->function_table);
454-
int count_static_funcs = 0;
454+
uint32_t count_static_funcs = 0;
455455
if (count > 0) {
456456
ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, zend_function *mptr) {
457457
if ((mptr->common.fn_flags & ZEND_ACC_STATIC)
@@ -463,7 +463,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const
463463
}
464464

465465
/* static methods */
466-
smart_str_append_printf(str, "\n%s - Static methods [%d] {", indent, count_static_funcs);
466+
smart_str_append_printf(str, "\n%s - Static methods [%u] {", indent, count_static_funcs);
467467
if (count_static_funcs > 0) {
468468
ZEND_HASH_MAP_FOREACH_PTR(&ce->function_table, zend_function *mptr) {
469469
if ((mptr->common.fn_flags & ZEND_ACC_STATIC)
@@ -480,7 +480,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const
480480

481481
/* Default/Implicit properties */
482482
count = zend_hash_num_elements(&ce->properties_info) - count_static_props - count_shadow_props;
483-
smart_str_append_printf(str, "\n%s - Properties [%d] {\n", indent, count);
483+
smart_str_append_printf(str, "\n%s - Properties [%u] {\n", indent, count);
484484
if (count > 0) {
485485
ZEND_HASH_MAP_FOREACH_PTR(&ce->properties_info, zend_property_info *prop) {
486486
if (!(prop->flags & ZEND_ACC_STATIC)
@@ -539,7 +539,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, const
539539
_free_function(closure);
540540
}
541541
} ZEND_HASH_FOREACH_END();
542-
smart_str_append_printf(str, "\n%s - Methods [%d] {", indent, count);
542+
smart_str_append_printf(str, "\n%s - Methods [%u] {", indent, count);
543543
smart_str_append_smart_str(str, &method_str);
544544
if (!count) {
545545
smart_str_appendc(str, '\n');
@@ -749,7 +749,7 @@ static void format_default_value(smart_str *str, const zval *value) {
749749
/* {{{ _parameter_string */
750750
static void _parameter_string(smart_str *str, const zend_function *fptr, const struct _zend_arg_info *arg_info, uint32_t offset, bool required)
751751
{
752-
smart_str_append_printf(str, "Parameter #%d [ ", offset);
752+
smart_str_append_printf(str, "Parameter #%u [ ", offset);
753753
if (!required) {
754754
smart_str_appends(str, "<optional> ");
755755
} else {
@@ -806,7 +806,7 @@ static void _function_parameter_string(smart_str *str, const zend_function *fptr
806806
uint32_t num_required = fptr->common.required_num_args;
807807

808808
smart_str_appendc(str, '\n');
809-
smart_str_append_printf(str, "%s- Parameters [%d] {\n", indent, num_args);
809+
smart_str_append_printf(str, "%s- Parameters [%u] {\n", indent, num_args);
810810
for (uint32_t i = 0; i < num_args; i++) {
811811
smart_str_append_printf(str, "%s ", indent);
812812
_parameter_string(str, fptr, arg_info, i, i < num_required);
@@ -835,7 +835,7 @@ static void _function_closure_string(smart_str *str, const zend_function *fptr,
835835
smart_str_append_printf(str, "%s- Bound Variables [%u] {\n", indent, count);
836836
uint32_t i = 0;
837837
ZEND_HASH_MAP_FOREACH_STR_KEY(static_variables, const zend_string *key) {
838-
smart_str_append_printf(str, "%s Variable #%d [ $%s ]\n", indent, i++, ZSTR_VAL(key));
838+
smart_str_append_printf(str, "%s Variable #%u [ $%s ]\n", indent, i++, ZSTR_VAL(key));
839839
} ZEND_HASH_FOREACH_END();
840840
smart_str_append_printf(str, "%s}\n", indent);
841841
}
@@ -929,7 +929,7 @@ static void _function_string(smart_str *str, const zend_function *fptr, const ze
929929
smart_str_append_printf(str, "%s ] {\n", ZSTR_VAL(fptr->common.function_name));
930930
/* The information where a function is declared is only available for user classes */
931931
if (fptr->type == ZEND_USER_FUNCTION) {
932-
smart_str_append_printf(str, "%s @@ %s %d - %d\n", indent,
932+
smart_str_append_printf(str, "%s @@ %s %u - %u\n", indent,
933933
ZSTR_VAL(fptr->op_array.filename),
934934
fptr->op_array.line_start,
935935
fptr->op_array.line_end);
@@ -1113,7 +1113,7 @@ static void _extension_ini_string(const zend_ini_entry *ini_entry, smart_str *st
11131113
}
11141114
/* }}} */
11151115

1116-
static void _extension_class_string(zend_class_entry *ce, zend_string *key, smart_str *str, const char *indent, const zend_module_entry *module, int *num_classes) /* {{{ */
1116+
static void _extension_class_string(zend_class_entry *ce, zend_string *key, smart_str *str, const char *indent, const zend_module_entry *module, uint32_t *num_classes) /* {{{ */
11171117
{
11181118
if (ce->type == ZEND_INTERNAL_CLASS
11191119
&& ce->info.internal.module
@@ -1191,7 +1191,7 @@ static void _extension_string(smart_str *str, const zend_module_entry *module) /
11911191

11921192
{
11931193
smart_str str_constants = {0};
1194-
int num_constants = 0;
1194+
uint32_t num_constants = 0;
11951195

11961196
ZEND_HASH_MAP_FOREACH_PTR(EG(zend_constants), zend_constant *constant) {
11971197
if (ZEND_CONSTANT_MODULE_NUMBER(constant) == module->module_number) {
@@ -1201,7 +1201,7 @@ static void _extension_string(smart_str *str, const zend_module_entry *module) /
12011201
} ZEND_HASH_FOREACH_END();
12021202

12031203
if (num_constants) {
1204-
smart_str_append_printf(str, "\n - Constants [%d] {\n", num_constants);
1204+
smart_str_append_printf(str, "\n - Constants [%u] {\n", num_constants);
12051205
smart_str_append_smart_str(str, &str_constants);
12061206
smart_str_appends(str, " }\n");
12071207
}
@@ -1229,13 +1229,13 @@ static void _extension_string(smart_str *str, const zend_module_entry *module) /
12291229

12301230
{
12311231
smart_str str_classes = {0};
1232-
int num_classes = 0;
1232+
uint32_t num_classes = 0;
12331233

12341234
ZEND_HASH_MAP_FOREACH_STR_KEY_PTR(EG(class_table), zend_string *key, zend_class_entry *ce) {
12351235
_extension_class_string(ce, key, &str_classes, " ", module, &num_classes);
12361236
} ZEND_HASH_FOREACH_END();
12371237
if (num_classes) {
1238-
smart_str_append_printf(str, "\n - Classes [%d] {", num_classes);
1238+
smart_str_append_printf(str, "\n - Classes [%u] {", num_classes);
12391239
smart_str_append_smart_str(str, &str_classes);
12401240
smart_str_appends(str, " }\n");
12411241
}
@@ -4961,7 +4961,7 @@ ZEND_METHOD(ReflectionClass, newInstance)
49614961
}
49624962

49634963
zval *params;
4964-
int num_args;
4964+
uint32_t num_args;
49654965
HashTable *named_params;
49664966
ZEND_PARSE_PARAMETERS_START(0, -1)
49674967
Z_PARAM_VARIADIC_WITH_NAMED(params, num_args, named_params)
@@ -5013,7 +5013,7 @@ ZEND_METHOD(ReflectionClass, newInstanceArgs)
50135013
RETURN_THROWS();
50145014
}
50155015

5016-
int argc = 0;
5016+
uint32_t argc = 0;
50175017
if (args) {
50185018
argc = zend_hash_num_elements(args);
50195019
}
@@ -7334,10 +7334,10 @@ ZEND_METHOD(ReflectionAttribute, __toString)
73347334

73357335
if (attr->data->argc > 0) {
73367336
smart_str_appends(&str, " {\n");
7337-
smart_str_append_printf(&str, " - Arguments [%d] {\n", attr->data->argc);
7337+
smart_str_append_printf(&str, " - Arguments [%u] {\n", attr->data->argc);
73387338

73397339
for (uint32_t i = 0; i < attr->data->argc; i++) {
7340-
smart_str_append_printf(&str, " Argument #%d [ ", i);
7340+
smart_str_append_printf(&str, " Argument #%u [ ", i);
73417341
if (attr->data->args[i].name != NULL) {
73427342
smart_str_append(&str, attr->data->args[i].name);
73437343
smart_str_appends(&str, " = ");
@@ -7984,7 +7984,7 @@ static void reflection_constant_find_ext(INTERNAL_FUNCTION_PARAMETERS, bool only
79847984
ZEND_PARSE_PARAMETERS_NONE();
79857985

79867986
GET_REFLECTION_OBJECT_PTR(const_);
7987-
int module_number = ZEND_CONSTANT_MODULE_NUMBER(const_);
7987+
uint32_t module_number = ZEND_CONSTANT_MODULE_NUMBER(const_);
79887988
if (module_number == PHP_USER_CONSTANT) {
79897989
// For user constants, ReflectionConstant::getExtension() returns null,
79907990
// ReflectionConstant::getExtensionName() returns false
@@ -8007,7 +8007,7 @@ static void reflection_constant_find_ext(INTERNAL_FUNCTION_PARAMETERS, bool only
80078007
zend_throw_exception_ex(
80088008
reflection_exception_ptr,
80098009
0,
8010-
"Unable to locate extension with module_number %d that provides constant %s",
8010+
"Unable to locate extension with module_number %u that provides constant %s",
80118011
module_number,
80128012
ZSTR_VAL(const_->name)
80138013
);

0 commit comments

Comments
 (0)