]> granicus.if.org Git - php/commitdiff
http_build_query() cannot fail
authorNikita Popov <nikita.ppv@gmail.com>
Tue, 22 Sep 2020 09:30:02 +0000 (11:30 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Tue, 22 Sep 2020 09:30:02 +0000 (11:30 +0200)
Assert that ht is not null and make php_url_encode_hash_ex() return
void to clarify that this is an infallible function.

ext/opcache/Optimizer/zend_func_info.c
ext/standard/basic_functions.stub.php
ext/standard/basic_functions_arginfo.h
ext/standard/http.c
ext/standard/php_http.h

index 87ec2e1ffa9eb30db9bcf7cc8c649d76b4cb2417..043a660d6c406984507ec06bcce235c0c4ebacff 100644 (file)
@@ -188,7 +188,7 @@ static const func_info_t func_infos[] = {
        F1("urldecode",                    MAY_BE_STRING),
        F1("rawurlencode",                 MAY_BE_STRING),
        F1("rawurldecode",                 MAY_BE_STRING),
-       F1("http_build_query",             MAY_BE_FALSE | MAY_BE_STRING),
+       F1("http_build_query",             MAY_BE_STRING),
 #if defined(HAVE_SYMLINK) || defined(PHP_WIN32)
        F1("readlink",                     MAY_BE_FALSE | MAY_BE_STRING),
 #endif
@@ -344,7 +344,7 @@ static const func_info_t func_infos[] = {
        F0("syslog",                       MAY_BE_TRUE),
        F0("closelog",                     MAY_BE_TRUE),
 #endif
-       F1("metaphone",                    MAY_BE_FALSE | MAY_BE_STRING),
+       F1("metaphone",                    MAY_BE_STRING),
        F1("ob_get_flush",                 MAY_BE_FALSE | MAY_BE_STRING),
        F1("ob_get_clean",                 MAY_BE_FALSE | MAY_BE_STRING),
        F1("ob_get_status",                MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_ANY | MAY_BE_ARRAY_OF_LONG | MAY_BE_ARRAY_OF_STRING | MAY_BE_ARRAY_OF_ARRAY),
index 0f59a2bdcd52cdd4cb4b6e74daf843ce54be0419..bd185d53820409a6646ae561695c0da211ea174d 100755 (executable)
@@ -978,7 +978,7 @@ function pfsockopen(string $hostname, int $port = -1, &$errno = null, &$errstr =
 
 /* http.c */
 
-function http_build_query(array|object $data, string $numeric_prefix = "", ?string $arg_separator = null, int $enc_type = PHP_QUERY_RFC1738): string|false {}
+function http_build_query(array|object $data, string $numeric_prefix = "", ?string $arg_separator = null, int $enc_type = PHP_QUERY_RFC1738): string {}
 
 /* image.c */
 
index 6ca9dfc34c46326fd09602126e24aabc183bf124..64f35950a4c5743e860bf9c6688eb323611cb210 100644 (file)
@@ -1,5 +1,5 @@
 /* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 02f033de2ff8c06e24b22b150baa1a503ce6b95e */
+ * Stub hash: d840ea5a32c8414bdc29e21635e7a36ee7c202e1 */
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
        ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0)
@@ -1501,7 +1501,7 @@ ZEND_END_ARG_INFO()
 
 #define arginfo_pfsockopen arginfo_fsockopen
 
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_http_build_query, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_http_build_query, 0, 1, IS_STRING, 0)
        ZEND_ARG_TYPE_MASK(0, data, MAY_BE_ARRAY|MAY_BE_OBJECT, NULL)
        ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, numeric_prefix, IS_STRING, 0, "\"\"")
        ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, arg_separator, IS_STRING, 1, "null")
index 804940fd1a63e17abff61f550356b5f4ac121e3c..18b7c6070bb03afb883f8e09cbc9e6e3f06e7b56 100644 (file)
@@ -21,7 +21,7 @@
 #define URL_DEFAULT_ARG_SEP "&"
 
 /* {{{ php_url_encode_hash */
-PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
+PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
                                const char *num_prefix, size_t num_prefix_len,
                                const char *key_prefix, size_t key_prefix_len,
                                const char *key_suffix, size_t key_suffix_len,
@@ -33,14 +33,11 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
        size_t arg_sep_len, newprefix_len, prop_len;
        zend_ulong idx;
        zval *zdata = NULL;
-
-       if (!ht) {
-               return FAILURE;
-       }
+       ZEND_ASSERT(ht);
 
        if (GC_IS_RECURSIVE(ht)) {
                /* Prevent recursion */
-               return SUCCESS;
+               return;
        }
 
        if (!arg_sep) {
@@ -219,8 +216,6 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
                        }
                }
        } ZEND_HASH_FOREACH_END();
-
-       return SUCCESS;
 }
 /* }}} */
 
@@ -241,12 +236,7 @@ PHP_FUNCTION(http_build_query)
                Z_PARAM_LONG(enc_type)
        ZEND_PARSE_PARAMETERS_END();
 
-       if (php_url_encode_hash_ex(HASH_OF(formdata), &formstr, prefix, prefix_len, NULL, 0, NULL, 0, (Z_TYPE_P(formdata) == IS_OBJECT ? formdata : NULL), arg_sep, (int)enc_type) == FAILURE) {
-               if (formstr.s) {
-                       smart_str_free(&formstr);
-               }
-               RETURN_FALSE;
-       }
+       php_url_encode_hash_ex(HASH_OF(formdata), &formstr, prefix, prefix_len, NULL, 0, NULL, 0, (Z_TYPE_P(formdata) == IS_OBJECT ? formdata : NULL), arg_sep, (int)enc_type);
 
        if (!formstr.s) {
                RETURN_EMPTY_STRING();
index b77cd0bda38bf8d49a17b59127e4d5e1699501e9..1df941ee0094945b0082cb3f75547ca30fef4d5e 100644 (file)
@@ -20,7 +20,7 @@
 #include "php.h"
 #include "zend_smart_str.h"
 
-PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
+PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
                                const char *num_prefix, size_t num_prefix_len,
                                const char *key_prefix, size_t key_prefix_len,
                                const char *key_suffix, size_t key_suffix_len,