Skip to content

Commit ca08e5f

Browse files
committed
ext/session: reduce scope of variables
1 parent 9026396 commit ca08e5f

File tree

1 file changed

+12
-24
lines changed

1 file changed

+12
-24
lines changed

ext/session/session.c

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -995,27 +995,25 @@ PS_SERIALIZER_ENCODE_FUNC(php_binary)
995995

996996
PS_SERIALIZER_DECODE_FUNC(php_binary)
997997
{
998-
const char *p;
999998
const char *endptr = val + vallen;
1000-
zend_string *name;
1001999
php_unserialize_data_t var_hash;
1002-
zval *current, rv;
10031000

10041001
PHP_VAR_UNSERIALIZE_INIT(var_hash);
10051002

1006-
for (p = val; p < endptr; ) {
1003+
for (const char *p = val; p < endptr; ) {
10071004
size_t namelen = ((unsigned char)(*p)) & (~PS_BIN_UNDEF);
10081005

10091006
if (namelen > PS_BIN_MAX || (p + namelen) >= endptr) {
10101007
PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
10111008
return FAILURE;
10121009
}
10131010

1014-
name = zend_string_init(p + 1, namelen, false);
1011+
zend_string *name = zend_string_init(p + 1, namelen, false);
10151012
p += namelen + 1;
1016-
current = var_tmp_var(&var_hash);
1013+
zval *current = var_tmp_var(&var_hash);
10171014

10181015
if (php_var_unserialize(current, (const unsigned char **) &p, (const unsigned char *) endptr, &var_hash)) {
1016+
zval rv;
10191017
ZVAL_PTR(&rv, current);
10201018
php_set_session_var(name, &rv, &var_hash);
10211019
} else {
@@ -1300,8 +1298,6 @@ static const php_session_cache_limiter_t php_session_cache_limiters[] = {
13001298

13011299
static int php_session_cache_limiter(void)
13021300
{
1303-
const php_session_cache_limiter_t *lim;
1304-
13051301
if (ZSTR_LEN(PS(cache_limiter)) == 0) {
13061302
return 0;
13071303
}
@@ -1313,7 +1309,7 @@ static int php_session_cache_limiter(void)
13131309
return -2;
13141310
}
13151311

1316-
for (lim = php_session_cache_limiters; lim->name; lim++) {
1312+
for (const php_session_cache_limiter_t *lim = php_session_cache_limiters; lim->name; lim++) {
13171313
if (!strcasecmp(lim->name, ZSTR_VAL(PS(cache_limiter)))) {
13181314
lim->func();
13191315
return 0;
@@ -1446,9 +1442,8 @@ PHPAPI const ps_module *_php_find_ps_module(const char *name)
14461442
PHPAPI const ps_serializer *_php_find_ps_serializer(const char *name)
14471443
{
14481444
const ps_serializer *found_serializer = NULL;
1449-
const ps_serializer *current_serializer;
14501445

1451-
for (current_serializer = ps_serializers; current_serializer->name; current_serializer++) {
1446+
for (const ps_serializer *current_serializer = ps_serializers; current_serializer->name; current_serializer++) {
14521447
if (!strcasecmp(name, current_serializer->name)) {
14531448
found_serializer = current_serializer;
14541449
break;
@@ -1643,16 +1638,14 @@ PHPAPI zend_result php_session_reset_id(void)
16431638

16441639
PHPAPI zend_result php_session_start(void)
16451640
{
1646-
const char *value;
1647-
16481641
switch (PS(session_status)) {
16491642
case php_session_active:
16501643
php_session_session_already_started_error(E_NOTICE, "Ignoring session_start() because a session has already been started");
16511644
return FAILURE;
16521645
break;
16531646

1654-
case php_session_disabled:
1655-
value = zend_ini_string(ZEND_STRL("session.save_handler"), false);
1647+
case php_session_disabled: {
1648+
const char *value = zend_ini_string(ZEND_STRL("session.save_handler"), false);
16561649
if (!PS(mod) && value) {
16571650
PS(mod) = _php_find_ps_module(value);
16581651
if (!PS(mod)) {
@@ -1670,6 +1663,7 @@ PHPAPI zend_result php_session_start(void)
16701663
}
16711664
PS(session_status) = php_session_none;
16721665
ZEND_FALLTHROUGH;
1666+
}
16731667

16741668
case php_session_none:
16751669
default:
@@ -1793,9 +1787,6 @@ PHP_FUNCTION(session_set_cookie_params)
17931787
}
17941788

17951789
if (options_ht) {
1796-
zend_string *key;
1797-
zval *value;
1798-
17991790
if (path) {
18001791
zend_argument_value_error(2, "must be null when argument #1 ($lifetime_or_options) is an array");
18011792
RETURN_THROWS();
@@ -1815,7 +1806,7 @@ PHP_FUNCTION(session_set_cookie_params)
18151806
zend_argument_value_error(5, "must be null when argument #1 ($lifetime_or_options) is an array");
18161807
RETURN_THROWS();
18171808
}
1818-
ZEND_HASH_FOREACH_STR_KEY_VAL(options_ht, key, value) {
1809+
ZEND_HASH_FOREACH_STR_KEY_VAL(options_ht, zend_string *key, zval *value) {
18191810
if (key) {
18201811
ZVAL_DEREF(value);
18211812
if (zend_string_equals_literal_ci(key, "lifetime")) {
@@ -2461,7 +2452,6 @@ PHP_FUNCTION(session_create_id)
24612452
PHP_FUNCTION(session_cache_limiter)
24622453
{
24632454
zend_string *limiter = NULL;
2464-
zend_string *ini_name;
24652455

24662456
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|S!", &limiter) == FAILURE) {
24672457
RETURN_THROWS();
@@ -2480,7 +2470,7 @@ PHP_FUNCTION(session_cache_limiter)
24802470
RETVAL_STRINGL(ZSTR_VAL(PS(cache_limiter)), ZSTR_LEN(PS(cache_limiter)));
24812471

24822472
if (limiter) {
2483-
ini_name = ZSTR_INIT_LITERAL("session.cache_limiter", false);
2473+
zend_string *ini_name = ZSTR_INIT_LITERAL("session.cache_limiter", false);
24842474
zend_alter_ini_entry(ini_name, limiter, PHP_INI_USER, PHP_INI_STAGE_RUNTIME);
24852475
zend_string_release_ex(ini_name, false);
24862476
}
@@ -2566,8 +2556,6 @@ static zend_result php_session_start_set_ini(zend_string *varname, zend_string *
25662556
PHP_FUNCTION(session_start)
25672557
{
25682558
zval *options = NULL;
2569-
zval *value;
2570-
zend_string *str_idx;
25712559
bool read_and_close = false;
25722560

25732561
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|a", &options) == FAILURE) {
@@ -2591,7 +2579,7 @@ PHP_FUNCTION(session_start)
25912579

25922580
/* set options */
25932581
if (options) {
2594-
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(options), str_idx, value) {
2582+
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(options), zend_string *str_idx, zval *value) {
25952583
if (UNEXPECTED(!str_idx)) {
25962584
zend_argument_value_error(1, "must be of type array with keys as string");
25972585
RETURN_THROWS();

0 commit comments

Comments
 (0)