]> granicus.if.org Git - php/commitdiff
Use zend_string* & more legible API for php_get_display_errors_mode()
authorGeorge Peter Banyard <girgias@php.net>
Sun, 14 Mar 2021 15:05:54 +0000 (15:05 +0000)
committerGeorge Peter Banyard <girgias@php.net>
Sun, 14 Mar 2021 15:06:15 +0000 (15:06 +0000)
main/main.c

index 144586e37202907f651adbc58a3827a5acf8c3fc..1aa41da672cb940be1e0e0112fe13ac4115dc163 100644 (file)
@@ -401,7 +401,7 @@ static PHP_INI_MH(OnUpdateTimeout)
 /* }}} */
 
 /* {{{ php_get_display_errors_mode() helper function */
-static zend_uchar php_get_display_errors_mode(char *value, size_t value_length)
+static zend_uchar php_get_display_errors_mode(zend_string *value)
 {
        zend_uchar mode;
 
@@ -409,24 +409,24 @@ static zend_uchar php_get_display_errors_mode(char *value, size_t value_length)
                return PHP_DISPLAY_ERRORS_STDOUT;
        }
 
-       if (value_length == 2 && !strcasecmp("on", value)) {
+       if (zend_string_equals_literal_ci(value, "on")) {
                return PHP_DISPLAY_ERRORS_STDOUT;
        }
-       if (value_length == 3 && !strcasecmp("yes", value)) {
+       if (zend_string_equals_literal_ci(value, "yes")) {
                return PHP_DISPLAY_ERRORS_STDOUT;
        }
 
-       if (value_length == 4 && !strcasecmp("true", value)) {
+       if (zend_string_equals_literal_ci(value, "true")) {
                return PHP_DISPLAY_ERRORS_STDOUT;
        }
-       if (value_length == 6 && !strcasecmp(value, "stderr")) {
+       if (zend_string_equals_literal_ci(value, "stderr")) {
                return PHP_DISPLAY_ERRORS_STDERR;
        }
-       if (value_length == 6 && !strcasecmp(value, "stdout")) {
+       if (zend_string_equals_literal_ci(value, "stdout")) {
                return PHP_DISPLAY_ERRORS_STDOUT;
        }
 
-       ZEND_ATOL(mode, value);
+       ZEND_ATOL(mode, ZSTR_VAL(value));
        if (mode && mode != PHP_DISPLAY_ERRORS_STDOUT && mode != PHP_DISPLAY_ERRORS_STDERR) {
                return PHP_DISPLAY_ERRORS_STDOUT;
        }
@@ -438,7 +438,7 @@ static zend_uchar php_get_display_errors_mode(char *value, size_t value_length)
 /* {{{ PHP_INI_MH */
 static PHP_INI_MH(OnUpdateDisplayErrors)
 {
-       PG(display_errors) = php_get_display_errors_mode(ZSTR_VAL(new_value), ZSTR_LEN(new_value));
+       PG(display_errors) = php_get_display_errors_mode(new_value);
 
        return SUCCESS;
 }
@@ -449,21 +449,17 @@ static PHP_INI_DISP(display_errors_mode)
 {
        zend_uchar mode;
        bool cgi_or_cli;
-       size_t tmp_value_length;
-       char *tmp_value;
+       zend_string *temporary_value;
 
        if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
-               tmp_value = (ini_entry->orig_value ? ZSTR_VAL(ini_entry->orig_value) : NULL );
-               tmp_value_length = (ini_entry->orig_value? ZSTR_LEN(ini_entry->orig_value) : 0);
+               temporary_value = (ini_entry->orig_value ? ini_entry->orig_value : NULL );
        } else if (ini_entry->value) {
-               tmp_value = ZSTR_VAL(ini_entry->value);
-               tmp_value_length = ZSTR_LEN(ini_entry->value);
+               temporary_value = ini_entry->value;
        } else {
-               tmp_value = NULL;
-               tmp_value_length = 0;
+               temporary_value = NULL;
        }
 
-       mode = php_get_display_errors_mode(tmp_value, tmp_value_length);
+       mode = php_get_display_errors_mode(temporary_value);
 
        /* Display 'On' for other SAPIs instead of STDOUT or STDERR */
        cgi_or_cli = (!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi") || !strcmp(sapi_module.name, "phpdbg"));