Skip to content

Commit 53bced3

Browse files
committed
ext/filter: Reduce scope of variables
1 parent 5cbfb69 commit 53bced3

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

ext/filter/filter.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ ZEND_GET_MODULE(filter)
100100

101101
static PHP_INI_MH(UpdateDefaultFilter) /* {{{ */
102102
{
103-
int i, size = sizeof(filter_list) / sizeof(filter_list_entry);
103+
int size = sizeof(filter_list) / sizeof(filter_list_entry);
104104

105-
for (i = 0; i < size; ++i) {
105+
for (int i = 0; i < size; ++i) {
106106
if ((strcasecmp(ZSTR_VAL(new_value), filter_list[i].name) == 0)) {
107107
IF_G(default_filter) = filter_list[i].id;
108108
if (IF_G(default_filter) != FILTER_DEFAULT) {
@@ -452,7 +452,6 @@ static void php_filter_call(
452452
zend_long filter_flags
453453
) /* {{{ */ {
454454
zval *options = NULL;
455-
zval *option;
456455
char *charset = NULL;
457456

458457
if (!filter_args_ht) {
@@ -467,6 +466,7 @@ static void php_filter_call(
467466
filter = filter_args_long;
468467
}
469468
} else {
469+
zval *option;
470470
if ((option = zend_hash_str_find(filter_args_ht, "filter", sizeof("filter") - 1)) != NULL) {
471471
filter = zval_get_long(option);
472472
}
@@ -527,14 +527,13 @@ static void php_filter_call(
527527
static void php_filter_array_handler(zval *input, HashTable *op_ht, zend_long op_long,
528528
zval *return_value, bool add_empty
529529
) /* {{{ */ {
530-
zend_string *arg_key;
531-
zval *tmp, *arg_elm;
532-
533530
if (!op_ht) {
534531
ZVAL_DUP(return_value, input);
535532
php_filter_call(return_value, -1, NULL, op_long, FILTER_REQUIRE_ARRAY);
536533
} else {
537534
array_init(return_value);
535+
zend_string *arg_key;
536+
zval *arg_elm;
538537

539538
ZEND_HASH_FOREACH_STR_KEY_VAL(op_ht, arg_key, arg_elm) {
540539
if (arg_key == NULL) {
@@ -545,6 +544,7 @@ static void php_filter_array_handler(zval *input, HashTable *op_ht, zend_long op
545544
zend_argument_value_error(2, "cannot contain empty keys");
546545
RETURN_THROWS();
547546
}
547+
zval *tmp;
548548
if ((tmp = zend_hash_find(Z_ARRVAL_P(input), arg_key)) == NULL) {
549549
if (add_empty) {
550550
add_assoc_null_ex(return_value, ZSTR_VAL(arg_key), ZSTR_LEN(arg_key));
@@ -594,10 +594,10 @@ PHP_FUNCTION(filter_input)
594594

595595
if (!input || (tmp = zend_hash_find(Z_ARRVAL_P(input), var)) == NULL) {
596596
zend_long filter_flags = 0;
597-
zval *option, *opt, *def;
598597
if (!filter_args_ht) {
599598
filter_flags = filter_args_long;
600599
} else {
600+
zval *option, *opt, *def;
601601
if ((option = zend_hash_str_find(filter_args_ht, "flags", sizeof("flags") - 1)) != NULL) {
602602
filter_flags = zval_get_long(option);
603603
}
@@ -717,14 +717,14 @@ PHP_FUNCTION(filter_var_array)
717717
/* {{{ Returns a list of all supported filters */
718718
PHP_FUNCTION(filter_list)
719719
{
720-
int i, size = sizeof(filter_list) / sizeof(filter_list_entry);
720+
int size = sizeof(filter_list) / sizeof(filter_list_entry);
721721

722722
if (zend_parse_parameters_none() == FAILURE) {
723723
RETURN_THROWS();
724724
}
725725

726726
array_init(return_value);
727-
for (i = 0; i < size; ++i) {
727+
for (int i = 0; i < size; ++i) {
728728
add_next_index_string(return_value, (char *)filter_list[i].name);
729729
}
730730
}
@@ -733,7 +733,6 @@ PHP_FUNCTION(filter_list)
733733
/* {{{ Returns the filter ID belonging to a named filter */
734734
PHP_FUNCTION(filter_id)
735735
{
736-
int i;
737736
size_t filter_len;
738737
int size = sizeof(filter_list) / sizeof(filter_list_entry);
739738
char *filter;
@@ -742,7 +741,7 @@ PHP_FUNCTION(filter_id)
742741
RETURN_THROWS();
743742
}
744743

745-
for (i = 0; i < size; ++i) {
744+
for (int i = 0; i < size; ++i) {
746745
if (strcmp(filter_list[i].name, filter) == 0) {
747746
RETURN_LONG(filter_list[i].id);
748747
}

ext/filter/logical_filters.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ void php_filter_validate_mac(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
10371037
{
10381038
char *input = Z_STRVAL_P(value);
10391039
size_t input_len = Z_STRLEN_P(value);
1040-
int tokens, length, i, offset, exp_separator_set;
1040+
int tokens, length, exp_separator_set;
10411041
size_t exp_separator_len;
10421042
char separator;
10431043
char *exp_separator;
@@ -1080,8 +1080,8 @@ void php_filter_validate_mac(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
10801080
* a hexadecimal number followed by a separator character. (With the
10811081
* exception of the last token which does not have the separator.)
10821082
*/
1083-
for (i = 0; i < tokens; i++) {
1084-
offset = i * (length + 1);
1083+
for (int i = 0; i < tokens; i++) {
1084+
int offset = i * (length + 1);
10851085

10861086
if (i < tokens - 1 && input[offset + length] != separator) {
10871087
/* The current token did not end with e.g. a "." */

ext/filter/sanitizing_filters.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ static void php_filter_encode_url(zval *value, const unsigned char* chars, const
9898
static void php_filter_strip(zval *value, zend_long flags)
9999
{
100100
unsigned char *str;
101-
size_t i;
102101
size_t c;
103102
zend_string *buf;
104103

@@ -110,7 +109,7 @@ static void php_filter_strip(zval *value, zend_long flags)
110109
str = (unsigned char *)Z_STRVAL_P(value);
111110
buf = zend_string_alloc(Z_STRLEN_P(value), 0);
112111
c = 0;
113-
for (i = 0; i < Z_STRLEN_P(value); i++) {
112+
for (size_t i = 0; i < Z_STRLEN_P(value); i++) {
114113
if ((str[i] >= 127) && (flags & FILTER_FLAG_STRIP_HIGH)) {
115114
} else if ((str[i] < 32) && (flags & FILTER_FLAG_STRIP_LOW)) {
116115
} else if ((str[i] == '`') && (flags & FILTER_FLAG_STRIP_BACKTICK)) {

0 commit comments

Comments
 (0)