Export zend_use_resource_as_offset()

Use a common implementation to generate this error message, as
we do so in quite a few places dealing with array keys.
This commit is contained in:
Nikita Popov 2021-08-31 10:58:01 +02:00
parent 7d6a7e78fc
commit 5b2ddf5a17
7 changed files with 11 additions and 12 deletions

View File

@ -1987,7 +1987,7 @@ ZEND_API zend_result array_set_zval_key(HashTable *ht, zval *key, zval *value) /
result = zend_hash_update(ht, ZSTR_EMPTY_ALLOC(), value);
break;
case IS_RESOURCE:
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(key), Z_RES_HANDLE_P(key));
zend_use_resource_as_offset(key);
result = zend_hash_index_update(ht, Z_RES_HANDLE_P(key), value);
break;
case IS_FALSE:

View File

@ -2164,7 +2164,7 @@ static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_cannot_add_element(vo
zend_throw_error(NULL, "Cannot add element to the array as the next element is already occupied");
}
static zend_never_inline ZEND_COLD void ZEND_FASTCALL zend_use_resource_as_offset(const zval *dim)
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_use_resource_as_offset(const zval *dim)
{
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
}

View File

@ -62,6 +62,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_missing_arg_error(zend_execute_data *
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_deprecated_function(const zend_function *fbc);
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_false_to_array_deprecated(void);
ZEND_COLD void ZEND_FASTCALL zend_param_must_be_ref(const zend_function *func, uint32_t arg_num);
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_use_resource_as_offset(const zval *dim);
ZEND_API bool ZEND_FASTCALL zend_verify_ref_assignable_zval(zend_reference *ref, zval *zv, bool strict);
ZEND_API bool ZEND_FASTCALL zend_verify_prop_assignable_by_ref(zend_property_info *prop_info, zval *orig_val, bool strict);

View File

@ -384,7 +384,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_r_helper(zend_array *ht, zval *dim,
hval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
goto num_index;
case IS_RESOURCE:
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
zend_use_resource_as_offset(dim);
hval = Z_RES_HANDLE_P(dim);
goto num_index;
case IS_FALSE:
@ -449,7 +449,7 @@ static void ZEND_FASTCALL zend_jit_fetch_dim_is_helper(zend_array *ht, zval *dim
hval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
goto num_index;
case IS_RESOURCE:
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
zend_use_resource_as_offset(dim);
hval = Z_RES_HANDLE_P(dim);
goto num_index;
case IS_FALSE:
@ -512,7 +512,7 @@ static int ZEND_FASTCALL zend_jit_fetch_dim_isset_helper(zend_array *ht, zval *d
hval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
goto num_index;
case IS_RESOURCE:
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
zend_use_resource_as_offset(dim);
hval = Z_RES_HANDLE_P(dim);
goto num_index;
case IS_FALSE:
@ -579,7 +579,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *di
hval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
goto num_index;
case IS_RESOURCE:
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
zend_use_resource_as_offset(dim);
hval = Z_RES_HANDLE_P(dim);
goto num_index;
case IS_FALSE:
@ -642,7 +642,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim
hval = zend_dval_to_lval_safe(Z_DVAL_P(dim));
goto num_index;
case IS_RESOURCE:
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
zend_use_resource_as_offset(dim);
hval = Z_RES_HANDLE_P(dim);
goto num_index;
case IS_FALSE:

View File

@ -303,8 +303,7 @@ try_again:
}
return SUCCESS;
case IS_RESOURCE:
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)",
Z_RES_P(offset)->handle, Z_RES_P(offset)->handle);
zend_use_resource_as_offset(offset);
key->key = NULL;
key->h = Z_RES_P(offset)->handle;
break;

View File

@ -333,8 +333,7 @@ static zend_long spl_offset_convert_to_long(zval *offset) /* {{{ */
offset = Z_REFVAL_P(offset);
goto try_again;
case IS_RESOURCE:
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)",
Z_RES_HANDLE_P(offset), Z_RES_HANDLE_P(offset));
zend_use_resource_as_offset(offset);
return Z_RES_HANDLE_P(offset);
}

View File

@ -6086,7 +6086,7 @@ PHP_FUNCTION(array_key_exists)
RETVAL_BOOL(zend_hash_index_exists(ht, 1));
break;
case IS_RESOURCE:
zend_error(E_WARNING, "Resource ID#%d used as offset, casting to integer (%d)", Z_RES_HANDLE_P(key), Z_RES_HANDLE_P(key));
zend_use_resource_as_offset(key);
RETVAL_BOOL(zend_hash_index_exists(ht, Z_RES_HANDLE_P(key)));
break;
default: