Skip to content

Commit 9666d7a

Browse files
committed
Don't check ZEND_TYPE_IS_SET() in zend_check_type()
Usually this function is only used if we already know that there is a type. Add checks to the places where we don't.
1 parent 1f497b3 commit 9666d7a

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

Zend/zend_execute.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -970,10 +970,7 @@ static zend_always_inline zend_bool zend_check_type(
970970
{
971971
zend_reference *ref = NULL;
972972
uint32_t type_mask;
973-
974-
if (!ZEND_TYPE_IS_SET(type)) {
975-
return 1;
976-
}
973+
ZEND_ASSERT(ZEND_TYPE_IS_SET(type));
977974

978975
if (UNEXPECTED(Z_ISREF_P(arg))) {
979976
ref = Z_REF_P(arg);
@@ -1023,12 +1020,13 @@ static zend_always_inline zend_bool zend_check_type(
10231020

10241021
static zend_always_inline int zend_verify_recv_arg_type(zend_function *zf, uint32_t arg_num, zval *arg, void **cache_slot)
10251022
{
1026-
zend_arg_info *cur_arg_info = &zf->common.arg_info[arg_num-1];
1023+
zend_arg_info *cur_arg_info;
10271024

10281025
ZEND_ASSERT(arg_num <= zf->common.num_args);
10291026
cur_arg_info = &zf->common.arg_info[arg_num-1];
10301027

1031-
if (UNEXPECTED(!zend_check_type(cur_arg_info->type, arg, cache_slot, zf->common.scope, 0, 0))) {
1028+
if (ZEND_TYPE_IS_SET(cur_arg_info->type)
1029+
&& UNEXPECTED(!zend_check_type(cur_arg_info->type, arg, cache_slot, zf->common.scope, 0, 0))) {
10321030
zend_verify_arg_error(zf, cur_arg_info, arg_num, cache_slot, arg);
10331031
return 0;
10341032
}
@@ -1070,7 +1068,8 @@ static zend_never_inline ZEND_ATTRIBUTE_UNUSED int zend_verify_internal_arg_type
10701068
break;
10711069
}
10721070

1073-
if (UNEXPECTED(!zend_check_type(cur_arg_info->type, arg, &dummy_cache_slot, fbc->common.scope, 0, /* is_internal */ 1))) {
1071+
if (ZEND_TYPE_IS_SET(cur_arg_info->type)
1072+
&& UNEXPECTED(!zend_check_type(cur_arg_info->type, arg, &dummy_cache_slot, fbc->common.scope, 0, /* is_internal */ 1))) {
10741073
return 0;
10751074
}
10761075
arg++;

0 commit comments

Comments
 (0)