Skip to content

Commit c8107cb

Browse files
committed
Prevent some variable shadowing
1 parent b80d508 commit c8107cb

11 files changed

+51
-58
lines changed

Zend/zend_compile.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -8003,9 +8003,8 @@ static void zend_compile_closure_uses(zend_ast *ast) /* {{{ */
80038003
ZVAL_NULL(&zv);
80048004

80058005
{
8006-
int i;
8007-
for (i = 0; i < op_array->last_var; i++) {
8008-
if (zend_string_equals(op_array->vars[i], var_name)) {
8006+
for (int var_index = 0; var_index < op_array->last_var; var_index++) {
8007+
if (zend_string_equals(op_array->vars[var_index], var_name)) {
80098008
zend_error_noreturn_unchecked(E_COMPILE_ERROR,
80108009
"Cannot use lexical variable $%S as a parameter name", var_name);
80118010
}

Zend/zend_inheritance.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -1328,9 +1328,9 @@ static inheritance_status verify_property_type_compatibility(
13281328
if (parent_info->hooks[ZEND_PROPERTY_HOOK_SET]
13291329
&& (!child_info->hooks || !child_info->hooks[ZEND_PROPERTY_HOOK_SET])) {
13301330
zend_type set_type = parent_info->hooks[ZEND_PROPERTY_HOOK_SET]->common.arg_info[0].type;
1331-
inheritance_status result = zend_perform_covariant_type_check(
1331+
inheritance_status hook_result = zend_perform_covariant_type_check(
13321332
parent_info->ce, set_type, child_info->ce, child_info->type);
1333-
if ((result == INHERITANCE_ERROR && throw_on_error) || (result == INHERITANCE_UNRESOLVED && throw_on_unresolved)) {
1333+
if ((hook_result == INHERITANCE_ERROR && throw_on_error) || (hook_result == INHERITANCE_UNRESOLVED && throw_on_unresolved)) {
13341334
emit_set_hook_type_error(child_info, parent_info);
13351335
}
13361336
}
@@ -2900,9 +2900,9 @@ static void zend_do_traits_property_binding(zend_class_entry *ce, zend_class_ent
29002900
zend_function **hooks = new_prop->hooks =
29012901
zend_arena_alloc(&CG(arena), ZEND_PROPERTY_HOOK_STRUCT_SIZE);
29022902
memcpy(hooks, property_info->hooks, ZEND_PROPERTY_HOOK_STRUCT_SIZE);
2903-
for (uint32_t i = 0; i < ZEND_PROPERTY_HOOK_COUNT; i++) {
2904-
if (hooks[i]) {
2905-
zend_function *old_fn = hooks[i];
2903+
for (uint32_t hook_index = 0; hook_index < ZEND_PROPERTY_HOOK_COUNT; hook_index++) {
2904+
if (hooks[hook_index]) {
2905+
const zend_function *old_fn = hooks[hook_index];
29062906

29072907
/* Hooks are not yet supported for internal properties. */
29082908
ZEND_ASSERT(ZEND_USER_CODE(old_fn->type));
@@ -2917,7 +2917,7 @@ static void zend_do_traits_property_binding(zend_class_entry *ce, zend_class_ent
29172917

29182918
zend_fixup_trait_method(new_fn, ce);
29192919

2920-
hooks[i] = new_fn;
2920+
hooks[hook_index] = new_fn;
29212921
}
29222922
}
29232923
ce->ce_flags |= ZEND_ACC_USE_GUARDS;

Zend/zend_operators.c

+5-9
Original file line numberDiff line numberDiff line change
@@ -3663,21 +3663,17 @@ ZEND_API uint8_t ZEND_FASTCALL _is_numeric_string_ex(const char *str, size_t len
36633663
* http://www.iti.fh-flensburg.de/lang/algorithmen/pattern/sundayen.htm
36643664
*/
36653665
static zend_always_inline void zend_memnstr_ex_pre(unsigned int td[], const char *needle, size_t needle_len, int reverse) /* {{{ */ {
3666-
int i;
3667-
3668-
for (i = 0; i < 256; i++) {
3666+
for (unsigned int i = 0; i < 256; i++) {
36693667
td[i] = needle_len + 1;
36703668
}
36713669

36723670
if (reverse) {
3673-
for (i = needle_len - 1; i >= 0; i--) {
3674-
td[(unsigned char)needle[i]] = i + 1;
3671+
for (size_t i = needle_len; i > 0; i--) {
3672+
td[(unsigned char)needle[i-1]] = i;
36753673
}
36763674
} else {
3677-
size_t i;
3678-
3679-
for (i = 0; i < needle_len; i++) {
3680-
td[(unsigned char)needle[i]] = (int)needle_len - i;
3675+
for (size_t i = 0; i < needle_len; i++) {
3676+
td[(unsigned char)needle[i]] = needle_len - i;
36813677
}
36823678
}
36833679
}

Zend/zend_vm_def.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -3240,8 +3240,7 @@ ZEND_VM_COLD_CONSTCONST_HANDLER(53, ZEND_FAST_CONCAT, CONST|TMPVAR|CV, CONST|TMP
32403240
{
32413241
USE_OPLINE
32423242
zval *op1, *op2;
3243-
zend_string *op1_str, *op2_str, *str;
3244-
3243+
zend_string *op1_str, *op2_str;
32453244

32463245
op1 = GET_OP1_ZVAL_PTR_UNDEF(BP_VAR_R);
32473246
op2 = GET_OP2_ZVAL_PTR_UNDEF(BP_VAR_R);
@@ -3343,7 +3342,7 @@ ZEND_VM_COLD_CONSTCONST_HANDLER(53, ZEND_FAST_CONCAT, CONST|TMPVAR|CV, CONST|TMP
33433342
break;
33443343
}
33453344
}
3346-
str = zend_string_alloc(ZSTR_LEN(op1_str) + ZSTR_LEN(op2_str), 0);
3345+
zend_string *str = zend_string_alloc(ZSTR_LEN(op1_str) + ZSTR_LEN(op2_str), 0);
33473346
memcpy(ZSTR_VAL(str), ZSTR_VAL(op1_str), ZSTR_LEN(op1_str));
33483347
memcpy(ZSTR_VAL(str) + ZSTR_LEN(op1_str), ZSTR_VAL(op2_str), ZSTR_LEN(op2_str)+1);
33493348

ext/pcre/php_pcre.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -1329,19 +1329,19 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, zend_string *subject_str,
13291329
* arrays with NULLs or empty strings.
13301330
*/
13311331
if (count < num_subpats) {
1332-
for (int i = count; i < num_subpats; i++) {
1332+
for (int subpattern = count; subpattern < num_subpats; subpattern++) {
13331333
if (offset_capture) {
13341334
add_offset_pair(
1335-
match_sets[i], NULL, PCRE2_UNSET, PCRE2_UNSET,
1335+
match_sets[subpattern], NULL, PCRE2_UNSET, PCRE2_UNSET,
13361336
NULL, unmatched_as_null);
13371337
} else if (unmatched_as_null) {
13381338
zval tmp;
13391339
ZVAL_NULL(&tmp);
1340-
zend_hash_next_index_insert_new(match_sets[i], &tmp);
1340+
zend_hash_next_index_insert_new(match_sets[subpattern], &tmp);
13411341
} else {
13421342
zval tmp;
13431343
ZVAL_EMPTY_STRING(&tmp);
1344-
zend_hash_next_index_insert_new(match_sets[i], &tmp);
1344+
zend_hash_next_index_insert_new(match_sets[subpattern], &tmp);
13451345
}
13461346
}
13471347
}

ext/spl/spl_iterators.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -2809,20 +2809,20 @@ PHP_METHOD(AppendIterator, __construct)
28092809
/* {{{ Append an iterator */
28102810
PHP_METHOD(AppendIterator, append)
28112811
{
2812-
spl_dual_it_object *intern;
2813-
zval *it;
2812+
spl_dual_it_object *intern;
2813+
zval *iterator;
28142814

2815-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &it, zend_ce_iterator) == FAILURE) {
2815+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &iterator, zend_ce_iterator) == FAILURE) {
28162816
RETURN_THROWS();
28172817
}
28182818

28192819
SPL_FETCH_AND_CHECK_DUAL_IT(intern, ZEND_THIS);
28202820

28212821
if (intern->u.append.iterator->funcs->valid(intern->u.append.iterator) == SUCCESS && spl_dual_it_valid(intern) != SUCCESS) {
2822-
spl_array_iterator_append(&intern->u.append.zarrayit, it);
2822+
spl_array_iterator_append(&intern->u.append.zarrayit, iterator);
28232823
intern->u.append.iterator->funcs->move_forward(intern->u.append.iterator);
28242824
}else{
2825-
spl_array_iterator_append(&intern->u.append.zarrayit, it);
2825+
spl_array_iterator_append(&intern->u.append.zarrayit, iterator);
28262826
}
28272827

28282828
if (!intern->inner.iterator || spl_dual_it_valid(intern) != SUCCESS) {

ext/spl/spl_observer.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,9 @@ static inline HashTable* spl_object_storage_debug_info(zend_object *obj) /* {{{
339339
/* Incrementing the refcount of obj and inf would confuse the garbage collector.
340340
* Prefer to null the destructor */
341341
Z_ARRVAL_P(&tmp)->pDestructor = NULL;
342-
zval obj;
343-
ZVAL_OBJ(&obj, element->obj);
344-
add_assoc_zval_ex(&tmp, "obj", sizeof("obj") - 1, &obj);
342+
zval element_obj;
343+
ZVAL_OBJ(&element_obj, element->obj);
344+
add_assoc_zval_ex(&tmp, "obj", sizeof("obj") - 1, &element_obj);
345345
add_assoc_zval_ex(&tmp, "inf", sizeof("inf") - 1, &element->inf);
346346
zend_hash_next_index_insert(Z_ARRVAL(storage), &tmp);
347347
} ZEND_HASH_FOREACH_END();

ext/standard/array.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -4209,10 +4209,10 @@ static zend_always_inline void php_array_replace_wrapper(INTERNAL_FUNCTION_PARAM
42094209

42104210

42114211
for (i = 0; i < argc; i++) {
4212-
zval *arg = args + i;
4212+
zval *check_arg = args + i;
42134213

4214-
if (Z_TYPE_P(arg) != IS_ARRAY) {
4215-
zend_argument_type_error(i + 1, "must be of type array, %s given", zend_zval_value_name(arg));
4214+
if (Z_TYPE_P(check_arg) != IS_ARRAY) {
4215+
zend_argument_type_error(i + 1, "must be of type array, %s given", zend_zval_value_name(check_arg));
42164216
RETURN_THROWS();
42174217
}
42184218
}
@@ -4264,13 +4264,13 @@ static zend_always_inline void php_array_merge_wrapper(INTERNAL_FUNCTION_PARAMET
42644264
}
42654265

42664266
for (i = 0; i < argc; i++) {
4267-
zval *arg = args + i;
4267+
zval *check_arg = args + i;
42684268

4269-
if (Z_TYPE_P(arg) != IS_ARRAY) {
4270-
zend_argument_type_error(i + 1, "must be of type array, %s given", zend_zval_value_name(arg));
4269+
if (Z_TYPE_P(check_arg) != IS_ARRAY) {
4270+
zend_argument_type_error(i + 1, "must be of type array, %s given", zend_zval_value_name(check_arg));
42714271
RETURN_THROWS();
42724272
}
4273-
count += zend_hash_num_elements(Z_ARRVAL_P(arg));
4273+
count += zend_hash_num_elements(Z_ARRVAL_P(check_arg));
42744274
}
42754275

42764276
if (argc == 2) {

ext/standard/dns.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,10 @@ static uint8_t *php_parserr(uint8_t *cp, uint8_t *end, querybuf *answer, int typ
576576
{
577577
int l1 = 0, l2 = 0;
578578
zval entries;
579-
zend_string *tp;
579+
zend_string *tp_str;
580580

581581
add_assoc_string(subarray, "type", "TXT");
582-
tp = zend_string_alloc(dlen, 0);
582+
tp_str = zend_string_alloc(dlen, 0);
583583

584584
array_init(&entries);
585585

@@ -590,17 +590,17 @@ static uint8_t *php_parserr(uint8_t *cp, uint8_t *end, querybuf *answer, int typ
590590
n = dlen - (l1 + 1);
591591
}
592592
if (n) {
593-
memcpy(ZSTR_VAL(tp) + l2 , cp + l1 + 1, n);
593+
memcpy(ZSTR_VAL(tp_str) + l2 , cp + l1 + 1, n);
594594
add_next_index_stringl(&entries, (char *) cp + l1 + 1, n);
595595
}
596596
l1 = l1 + n + 1;
597597
l2 = l2 + n;
598598
}
599-
ZSTR_VAL(tp)[l2] = '\0';
600-
ZSTR_LEN(tp) = l2;
599+
ZSTR_VAL(tp_str)[l2] = '\0';
600+
ZSTR_LEN(tp_str) = l2;
601601
cp += dlen;
602602

603-
add_assoc_str(subarray, "txt", tp);
603+
add_assoc_str(subarray, "txt", tp_str);
604604
add_assoc_zval(subarray, "entries", &entries);
605605
}
606606
break;

ext/standard/levenshtein.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* reference implementation, only optimized for memory usage, not speed */
2121
static zend_long reference_levdist(const zend_string *string1, const zend_string *string2, zend_long cost_ins, zend_long cost_rep, zend_long cost_del )
2222
{
23-
zend_long *p1, *p2, *tmp;
23+
zend_long *p1, *p2;
2424
zend_long c0, c1, c2;
2525
size_t i1, i2;
2626

@@ -61,7 +61,7 @@ static zend_long reference_levdist(const zend_string *string1, const zend_string
6161
}
6262
p2[i2 + 1] = c0;
6363
}
64-
tmp = p1;
64+
zend_long *tmp = p1;
6565
p1 = p2;
6666
p2 = tmp;
6767
}

ext/standard/var.c

+9-10
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,7 @@ static const char *php_var_dump_object_prefix(zend_object *obj) {
103103
PHPAPI void php_var_dump(zval *struc, int level) /* {{{ */
104104
{
105105
HashTable *myht;
106-
zend_string *class_name;
107106
int is_ref = 0;
108-
zend_ulong num;
109-
zend_string *key;
110-
zval *val;
111-
uint32_t count;
112107

113108
if (level > 1) {
114109
php_printf("%*c", level - 1, ' ');
@@ -136,7 +131,7 @@ PHPAPI void php_var_dump(zval *struc, int level) /* {{{ */
136131
PHPWRITE(Z_STRVAL_P(struc), Z_STRLEN_P(struc));
137132
PUTS("\"\n");
138133
break;
139-
case IS_ARRAY:
134+
case IS_ARRAY: {
140135
myht = Z_ARRVAL_P(struc);
141136
if (!(GC_FLAGS(myht) & GC_IMMUTABLE)) {
142137
if (GC_IS_RECURSIVE(myht)) {
@@ -146,8 +141,11 @@ PHPAPI void php_var_dump(zval *struc, int level) /* {{{ */
146141
GC_ADDREF(myht);
147142
GC_PROTECT_RECURSION(myht);
148143
}
149-
count = zend_hash_num_elements(myht);
144+
uint32_t count = zend_hash_num_elements(myht);
150145
php_printf("%sarray(%d) {\n", COMMON, count);
146+
zend_ulong num;
147+
zend_string *key;
148+
zval *val;
151149
ZEND_HASH_FOREACH_KEY_VAL(myht, num, key, val) {
152150
php_array_element_dump(val, num, key, level);
153151
} ZEND_HASH_FOREACH_END();
@@ -160,6 +158,7 @@ PHPAPI void php_var_dump(zval *struc, int level) /* {{{ */
160158
}
161159
PUTS("}\n");
162160
break;
161+
}
163162
case IS_OBJECT: {
164163
zend_class_entry *ce = Z_OBJCE_P(struc);
165164
if (ce->ce_flags & ZEND_ACC_ENUM) {
@@ -176,7 +175,7 @@ PHPAPI void php_var_dump(zval *struc, int level) /* {{{ */
176175
ZEND_GUARD_OR_GC_PROTECT_RECURSION(guard, DEBUG, zobj);
177176

178177
myht = zend_get_properties_for(struc, ZEND_PROP_PURPOSE_DEBUG);
179-
class_name = Z_OBJ_HANDLER_P(struc, get_class_name)(Z_OBJ_P(struc));
178+
zend_string *class_name = Z_OBJ_HANDLER_P(struc, get_class_name)(Z_OBJ_P(struc));
180179
const char *prefix = php_var_dump_object_prefix(Z_OBJ_P(struc));
181180

182181
php_printf("%s%sobject(%s)#%d (%d) {\n", COMMON, prefix, ZSTR_VAL(class_name), Z_OBJ_HANDLE_P(struc), myht ? zend_array_count(myht) : 0);
@@ -616,8 +615,8 @@ PHPAPI zend_result php_var_export_ex(zval *struc, int level, smart_str *buf) /*
616615
smart_str_appendc(buf, '\\');
617616
smart_str_append(buf, ce->name);
618617
if (is_enum) {
619-
zend_object *zobj = Z_OBJ_P(struc);
620-
zval *case_name_zval = zend_enum_fetch_case_name(zobj);
618+
zend_object *enum_obj = Z_OBJ_P(struc);
619+
zval *case_name_zval = zend_enum_fetch_case_name(enum_obj);
621620
smart_str_appendl(buf, "::", 2);
622621
smart_str_append(buf, Z_STR_P(case_name_zval));
623622
} else {

0 commit comments

Comments
 (0)