diff options
author | Xinchen Hui <laruence@gmail.com> | 2018-08-17 15:21:48 +0800 |
---|---|---|
committer | Xinchen Hui <laruence@gmail.com> | 2018-08-17 15:21:48 +0800 |
commit | 0a16af043e24a2c55d9bc4f7bf552dee96fcedcc (patch) | |
tree | 93991933cf15c9bbbadca13e3db4a68240ead38e | |
parent | 751bbaa41fd64cf39554d75b8b8f02629f90de78 (diff) | |
download | php-git-0a16af043e24a2c55d9bc4f7bf552dee96fcedcc.tar.gz |
Cheaper checking
-rw-r--r-- | ext/standard/head.c | 31 |
1 files changed, 11 insertions, 20 deletions
diff --git a/ext/standard/head.c b/ext/standard/head.c index c202e8f952..07b9a93cf2 100644 --- a/ext/standard/head.c +++ b/ext/standard/head.c @@ -206,17 +206,11 @@ PHPAPI int php_setcookie(zend_string *name, zend_string *value, time_t expires, return result; } -static int php_head_parse_cookie_options_array(zval *options, zend_long *expires, zend_string **path, zend_string **domain, zend_bool *secure, zend_bool *httponly, zend_string **samesite) { +static void php_head_parse_cookie_options_array(zval *options, zend_long *expires, zend_string **path, zend_string **domain, zend_bool *secure, zend_bool *httponly, zend_string **samesite) { int found = 0; zend_string *key; zval *value; - if (*path) { - *path = NULL; - php_error_docref(NULL, E_WARNING, "Cannot pass arguments after the options array"); - return 0; - } - ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(options), key, value) { if (key) { if (zend_string_equals_literal_ci(key, "expires")) { @@ -249,8 +243,6 @@ static int php_head_parse_cookie_options_array(zval *options, zend_long *expires if (found == 0 && zend_hash_num_elements(Z_ARRVAL_P(options)) > 0) { php_error_docref(NULL, E_WARNING, "No valid options were found in the given array"); } - - return 1; } /* {{{ proto bool setcookie(string name [, string value [, int expires [, string path [, string domain [, bool secure[, bool httponly]]]]]]) @@ -276,10 +268,11 @@ PHP_FUNCTION(setcookie) if (expires_or_options) { if (Z_TYPE_P(expires_or_options) == IS_ARRAY) { - if (!php_head_parse_cookie_options_array(expires_or_options, &expires, &path, &domain, &secure, &httponly, &samesite)) { - RETVAL_FALSE; - goto cleanup; + if (UNEXPECTED(ZEND_NUM_ARGS() > 3)) { + php_error_docref(NULL, E_WARNING, "Cannot pass arguments after the options array"); + RETURN_FALSE; } + php_head_parse_cookie_options_array(expires_or_options, &expires, &path, &domain, &secure, &httponly, &samesite); } else { expires = zval_get_long(expires_or_options); } @@ -291,7 +284,6 @@ PHP_FUNCTION(setcookie) RETVAL_FALSE; } -cleanup: if (expires_or_options && Z_TYPE_P(expires_or_options) == IS_ARRAY) { if (path) { zend_string_release(path); @@ -314,7 +306,7 @@ PHP_FUNCTION(setrawcookie) zval *expires_or_options = NULL; zend_string *name, *value = NULL, *path = NULL, *domain = NULL, *samesite = NULL; zend_long expires = 0; - zend_bool secure = 0, httponly = 0, options_array = 0; + zend_bool secure = 0, httponly = 0; ZEND_PARSE_PARAMETERS_START(1, 7) Z_PARAM_STR(name) @@ -329,11 +321,11 @@ PHP_FUNCTION(setrawcookie) if (expires_or_options) { if (Z_TYPE_P(expires_or_options) == IS_ARRAY) { - options_array = 1; - if (!php_head_parse_cookie_options_array(expires_or_options, &expires, &path, &domain, &secure, &httponly, &samesite)) { - RETVAL_FALSE; - goto cleanup; + if (UNEXPECTED(ZEND_NUM_ARGS() > 3)) { + php_error_docref(NULL, E_WARNING, "Cannot pass arguments after the options array"); + RETURN_FALSE; } + php_head_parse_cookie_options_array(expires_or_options, &expires, &path, &domain, &secure, &httponly, &samesite); } else { expires = Z_LVAL_P(expires_or_options); } @@ -345,8 +337,7 @@ PHP_FUNCTION(setrawcookie) RETVAL_FALSE; } -cleanup: - if (options_array) { + if (expires_or_options && Z_TYPE_P(expires_or_options) == IS_ARRAY) { if (path) { zend_string_release(path); } |