Skip to content

Commit e547ea4

Browse files
committed
http_build_query() cannot fail
Assert that ht is not null and make php_url_encode_hash_ex() return void to clarify that this is an infallible function.
1 parent 0fbebfd commit e547ea4

File tree

5 files changed

+10
-20
lines changed

5 files changed

+10
-20
lines changed

ext/opcache/Optimizer/zend_func_info.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static const func_info_t func_infos[] = {
188188
F1("urldecode", MAY_BE_STRING),
189189
F1("rawurlencode", MAY_BE_STRING),
190190
F1("rawurldecode", MAY_BE_STRING),
191-
F1("http_build_query", MAY_BE_FALSE | MAY_BE_STRING),
191+
F1("http_build_query", MAY_BE_STRING),
192192
#if defined(HAVE_SYMLINK) || defined(PHP_WIN32)
193193
F1("readlink", MAY_BE_FALSE | MAY_BE_STRING),
194194
#endif
@@ -344,7 +344,7 @@ static const func_info_t func_infos[] = {
344344
F0("syslog", MAY_BE_TRUE),
345345
F0("closelog", MAY_BE_TRUE),
346346
#endif
347-
F1("metaphone", MAY_BE_FALSE | MAY_BE_STRING),
347+
F1("metaphone", MAY_BE_STRING),
348348
F1("ob_get_flush", MAY_BE_FALSE | MAY_BE_STRING),
349349
F1("ob_get_clean", MAY_BE_FALSE | MAY_BE_STRING),
350350
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),

ext/standard/basic_functions.stub.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ function pfsockopen(string $hostname, int $port = -1, &$errno = null, &$errstr =
978978

979979
/* http.c */
980980

981-
function http_build_query(array|object $data, string $numeric_prefix = "", ?string $arg_separator = null, int $enc_type = PHP_QUERY_RFC1738): string|false {}
981+
function http_build_query(array|object $data, string $numeric_prefix = "", ?string $arg_separator = null, int $enc_type = PHP_QUERY_RFC1738): string {}
982982

983983
/* image.c */
984984

ext/standard/basic_functions_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 02f033de2ff8c06e24b22b150baa1a503ce6b95e */
2+
* Stub hash: d840ea5a32c8414bdc29e21635e7a36ee7c202e1 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_set_time_limit, 0, 1, _IS_BOOL, 0)
55
ZEND_ARG_TYPE_INFO(0, seconds, IS_LONG, 0)
@@ -1501,7 +1501,7 @@ ZEND_END_ARG_INFO()
15011501

15021502
#define arginfo_pfsockopen arginfo_fsockopen
15031503

1504-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_http_build_query, 0, 1, MAY_BE_STRING|MAY_BE_FALSE)
1504+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_http_build_query, 0, 1, IS_STRING, 0)
15051505
ZEND_ARG_TYPE_MASK(0, data, MAY_BE_ARRAY|MAY_BE_OBJECT, NULL)
15061506
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, numeric_prefix, IS_STRING, 0, "\"\"")
15071507
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, arg_separator, IS_STRING, 1, "null")

ext/standard/http.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#define URL_DEFAULT_ARG_SEP "&"
2222

2323
/* {{{ php_url_encode_hash */
24-
PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
24+
PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
2525
const char *num_prefix, size_t num_prefix_len,
2626
const char *key_prefix, size_t key_prefix_len,
2727
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,
3333
size_t arg_sep_len, newprefix_len, prop_len;
3434
zend_ulong idx;
3535
zval *zdata = NULL;
36-
37-
if (!ht) {
38-
return FAILURE;
39-
}
36+
ZEND_ASSERT(ht);
4037

4138
if (GC_IS_RECURSIVE(ht)) {
4239
/* Prevent recursion */
43-
return SUCCESS;
40+
return;
4441
}
4542

4643
if (!arg_sep) {
@@ -219,8 +216,6 @@ PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
219216
}
220217
}
221218
} ZEND_HASH_FOREACH_END();
222-
223-
return SUCCESS;
224219
}
225220
/* }}} */
226221

@@ -241,12 +236,7 @@ PHP_FUNCTION(http_build_query)
241236
Z_PARAM_LONG(enc_type)
242237
ZEND_PARSE_PARAMETERS_END();
243238

244-
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) {
245-
if (formstr.s) {
246-
smart_str_free(&formstr);
247-
}
248-
RETURN_FALSE;
249-
}
239+
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);
250240

251241
if (!formstr.s) {
252242
RETURN_EMPTY_STRING();

ext/standard/php_http.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "php.h"
2121
#include "zend_smart_str.h"
2222

23-
PHPAPI int php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
23+
PHPAPI void php_url_encode_hash_ex(HashTable *ht, smart_str *formstr,
2424
const char *num_prefix, size_t num_prefix_len,
2525
const char *key_prefix, size_t key_prefix_len,
2626
const char *key_suffix, size_t key_suffix_len,

0 commit comments

Comments
 (0)