Skip to content

Commit 9108a32

Browse files
authored
Minor cleanups in Zend execution APIs (#10699)
* Remove always-false check in zend_lookup_class_ex() This check is always false because of the undefined behaviour rule that says a NULL pointer must never be dereferenced: we already dereference name when checking the cache slot, before the NULL check. So the NULL may be optimised away by the compiler. It looks like the code isn't even supposed to work with name being NULL, so just remove the check. * Remove always-true check in zend_fetch_static_property_address_ex() * Simplify always-true conditions
1 parent 9004725 commit 9108a32

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

Zend/zend_API.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -2749,7 +2749,7 @@ ZEND_API zend_result zend_register_functions(zend_class_entry *scope, const zend
27492749
if (ptr->flags) {
27502750
if (!(ptr->flags & ZEND_ACC_PPP_MASK)) {
27512751
if (ptr->flags != ZEND_ACC_DEPRECATED && scope) {
2752-
zend_error(error_type, "Invalid access level for %s%s%s() - access must be exactly one of public, protected or private", scope ? ZSTR_VAL(scope->name) : "", scope ? "::" : "", ptr->fname);
2752+
zend_error(error_type, "Invalid access level for %s::%s() - access must be exactly one of public, protected or private", ZSTR_VAL(scope->name), ptr->fname);
27532753
}
27542754
internal_function->fn_flags = ZEND_ACC_PUBLIC | ptr->flags;
27552755
} else {
@@ -3797,9 +3797,9 @@ static zend_always_inline bool zend_is_callable_check_func(zval *callable, zend_
37973797
}
37983798
} else if (error) {
37993799
if (fcc->calling_scope) {
3800-
if (error) zend_spprintf(error, 0, "class %s does not have a method \"%s\"", ZSTR_VAL(fcc->calling_scope->name), ZSTR_VAL(mname));
3800+
zend_spprintf(error, 0, "class %s does not have a method \"%s\"", ZSTR_VAL(fcc->calling_scope->name), ZSTR_VAL(mname));
38013801
} else {
3802-
if (error) zend_spprintf(error, 0, "function %s() does not exist", ZSTR_VAL(mname));
3802+
zend_spprintf(error, 0, "function %s() does not exist", ZSTR_VAL(mname));
38033803
}
38043804
}
38053805
zend_string_release_ex(lmname, 0);

Zend/zend_execute.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -3365,11 +3365,9 @@ static zend_never_inline zend_result zend_fetch_static_property_address_ex(zval
33653365
}
33663366
*retval = zend_std_get_static_property_with_info(ce, name, fetch_type, &property_info);
33673367

3368-
if (UNEXPECTED(op1_type != IS_CONST)) {
3369-
zend_tmp_string_release(tmp_name);
3368+
zend_tmp_string_release(tmp_name);
33703369

3371-
FREE_OP(op1_type, opline->op1.var);
3372-
}
3370+
FREE_OP(op1_type, opline->op1.var);
33733371
}
33743372

33753373
if (UNEXPECTED(*retval == NULL)) {

Zend/zend_execute_API.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ ZEND_API zend_class_entry *zend_lookup_class_ex(zend_string *name, zend_string *
11151115
if (key) {
11161116
lc_name = key;
11171117
} else {
1118-
if (name == NULL || !ZSTR_LEN(name)) {
1118+
if (!ZSTR_LEN(name)) {
11191119
return NULL;
11201120
}
11211121

0 commit comments

Comments
 (0)