]> granicus.if.org Git - php/commitdiff
Reduce var scope
authorAnatol Belski <ab@php.net>
Fri, 16 Feb 2018 14:43:54 +0000 (15:43 +0100)
committerAnatol Belski <ab@php.net>
Fri, 16 Feb 2018 14:44:43 +0000 (15:44 +0100)
sapi/cgi/cgi_main.c

index bdf6d34f0b7607d4d1a4edcae66c21739f67d5ba..2682cb674da540501a7260de115a7b6753756c43 100644 (file)
@@ -379,7 +379,6 @@ static void sapi_fcgi_flush(void *server_context)
 
 static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers)
 {
-       char buf[SAPI_CGI_MAX_HEADER_LENGTH];
        sapi_header_struct *h;
        zend_llist_position pos;
        zend_bool ignore_status = 0;
@@ -393,6 +392,7 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers)
        {
                int len;
                zend_bool has_status = 0;
+               char buf[SAPI_CGI_MAX_HEADER_LENGTH];
 
                if (CGIG(rfc2616_headers) && SG(sapi_headers).http_status_line) {
                        char *s;
@@ -790,7 +790,6 @@ static void sapi_cgi_log_message(char *message, int syslog_type_int)
  */
 static void php_cgi_ini_activate_user_config(char *path, size_t path_len, const char *doc_root, size_t doc_root_len, int start)
 {
-       char *ptr;
        user_config_cache_entry *new_entry, *entry;
        time_t request_time = (time_t)sapi_get_request_time();
 
@@ -806,7 +805,6 @@ static void php_cgi_ini_activate_user_config(char *path, size_t path_len, const
        /* Check whether cache entry has expired and rescan if it is */
        if (request_time > entry->expires) {
                char *real_path = NULL;
-               size_t real_path_len;
                char *s1, *s2;
                size_t s_len;
 
@@ -814,6 +812,7 @@ static void php_cgi_ini_activate_user_config(char *path, size_t path_len, const
                zend_hash_clean(entry->user_config);
 
                if (!IS_ABSOLUTE_PATH(path, path_len)) {
+                       size_t real_path_len;
                        real_path = tsrm_realpath(path, NULL);
                        if (real_path == NULL) {
                                return;
@@ -842,7 +841,7 @@ static void php_cgi_ini_activate_user_config(char *path, size_t path_len, const
 #else
                if (strncmp(s1, s2, s_len) == 0) {
 #endif
-                       ptr = s2 + start;  /* start is the point where doc_root ends! */
+                       char *ptr = s2 + start;  /* start is the point where doc_root ends! */
                        while ((ptr = strchr(ptr, DEFAULT_SLASH)) != NULL) {
                                *ptr = 0;
                                php_parse_user_ini_file(path, PG(user_ini_filename), entry->user_config);
@@ -866,15 +865,14 @@ static void php_cgi_ini_activate_user_config(char *path, size_t path_len, const
 
 static int sapi_cgi_activate(void)
 {
-       char *path, *doc_root, *server_name;
-       size_t path_len, doc_root_len, server_name_len;
-
        /* PATH_TRANSLATED should be defined at this stage but better safe than sorry :) */
        if (!SG(request_info).path_translated) {
                return FAILURE;
        }
 
        if (php_ini_has_per_host_config()) {
+               char *server_name;
+
                /* Activate per-host-system-configuration defined in php.ini and stored into configuration_hash during startup */
                if (fcgi_is_fastcgi()) {
                        fcgi_request *request = (fcgi_request*) SG(server_context);
@@ -885,7 +883,7 @@ static int sapi_cgi_activate(void)
                }
                /* SERVER_NAME should also be defined at this stage..but better check it anyway */
                if (server_name) {
-                       server_name_len = strlen(server_name);
+                       size_t server_name_len = strlen(server_name);
                        server_name = estrndup(server_name, server_name_len);
                        zend_str_tolower(server_name, server_name_len);
                        php_ini_activate_per_host_config(server_name, server_name_len);
@@ -896,6 +894,9 @@ static int sapi_cgi_activate(void)
        if (php_ini_has_per_dir_config() ||
                (PG(user_ini_filename) && *PG(user_ini_filename))
        ) {
+               char *path;
+               size_t path_len;
+
                /* Prepare search path */
                path_len = strlen(SG(request_info).path_translated);
 
@@ -916,6 +917,8 @@ static int sapi_cgi_activate(void)
 
                /* Load and activate user ini files in path starting from DOCUMENT_ROOT */
                if (PG(user_ini_filename) && *PG(user_ini_filename)) {
+                       char *doc_root;
+
                        if (fcgi_is_fastcgi()) {
                                fcgi_request *request = (fcgi_request*) SG(server_context);
 
@@ -925,7 +928,7 @@ static int sapi_cgi_activate(void)
                        }
                        /* DOCUMENT_ROOT should also be defined at this stage..but better check it anyway */
                        if (doc_root) {
-                               doc_root_len = strlen(doc_root);
+                               size_t doc_root_len = strlen(doc_root);
                                if (doc_root_len > 0 && IS_SLASH(doc_root[doc_root_len - 1])) {
                                        --doc_root_len;
                                }
@@ -1589,7 +1592,7 @@ static void add_request_header(char *var, unsigned int var_len, char *val, unsig
 {
        zval *return_value = (zval*)arg;
        char *str = NULL;
-       char *p;
+
        ALLOCA_FLAG(use_heap)
 
        if (var_len > 5 &&
@@ -1599,6 +1602,8 @@ static void add_request_header(char *var, unsigned int var_len, char *val, unsig
            var[3] == 'P' &&
            var[4] == '_') {
 
+               char *p;
+
                var_len -= 5;
                p = var + 5;
                var = str = do_alloca(var_len + 1, use_heap);
@@ -1718,12 +1723,12 @@ PHP_FUNCTION(apache_request_headers) /* {{{ */
 
 static void add_response_header(sapi_header_struct *h, zval *return_value) /* {{{ */
 {
-       char *s, *p;
-       size_t len = 0;
-       ALLOCA_FLAG(use_heap)
-
        if (h->header_len > 0) {
-               p = strchr(h->header, ':');
+               char *s;
+               size_t len = 0;
+               ALLOCA_FLAG(use_heap)
+
+               char *p = strchr(h->header, ':');
                if (NULL != p) {
                        len = p - h->header;
                }