Skip to content

Commit 74f1547

Browse files
carusogabrielnikic
authored andcommitted
Use zend_string in zend_check_magic_method implementation
1 parent d5e51fc commit 74f1547

File tree

1 file changed

+16
-32
lines changed

1 file changed

+16
-32
lines changed

Zend/zend_API.c

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1960,82 +1960,66 @@ ZEND_API zend_module_entry* zend_register_internal_module(zend_module_entry *mod
19601960

19611961
ZEND_API void zend_check_magic_method_implementation(const zend_class_entry *ce, const zend_function *fptr, int error_type) /* {{{ */
19621962
{
1963-
char lcname[16];
1964-
size_t name_len;
1963+
zend_string *lcname;
19651964

19661965
if (ZSTR_VAL(fptr->common.function_name)[0] != '_'
19671966
|| ZSTR_VAL(fptr->common.function_name)[1] != '_') {
19681967
return;
19691968
}
19701969

1971-
/* we don't care if the function name is longer, in fact lowercasing only
1972-
* the beginning of the name speeds up the check process */
1973-
name_len = ZSTR_LEN(fptr->common.function_name);
1974-
zend_str_tolower_copy(lcname, ZSTR_VAL(fptr->common.function_name), MIN(name_len, sizeof(lcname)-1));
1975-
lcname[sizeof(lcname)-1] = '\0'; /* zend_str_tolower_copy won't necessarily set the zero byte */
1970+
lcname = zend_string_tolower(fptr->common.function_name);
19761971

1977-
if (name_len == sizeof(ZEND_DESTRUCTOR_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_DESTRUCTOR_FUNC_NAME, sizeof(ZEND_DESTRUCTOR_FUNC_NAME) - 1) && fptr->common.num_args != 0) {
1972+
if (zend_string_equals_literal(lcname, ZEND_DESTRUCTOR_FUNC_NAME) && fptr->common.num_args != 0) {
19781973
zend_error(error_type, "Destructor %s::%s() cannot take arguments", ZSTR_VAL(ce->name), ZEND_DESTRUCTOR_FUNC_NAME);
1979-
} else if (name_len == sizeof(ZEND_CLONE_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_CLONE_FUNC_NAME, sizeof(ZEND_CLONE_FUNC_NAME) - 1) && fptr->common.num_args != 0) {
1974+
} else if (zend_string_equals_literal(lcname, ZEND_CLONE_FUNC_NAME) && fptr->common.num_args != 0) {
19801975
zend_error(error_type, "Method %s::%s() cannot accept any arguments", ZSTR_VAL(ce->name), ZEND_CLONE_FUNC_NAME);
1981-
} else if (name_len == sizeof(ZEND_GET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME) - 1)) {
1976+
} else if (zend_string_equals_literal(lcname, ZEND_GET_FUNC_NAME)) {
19821977
if (fptr->common.num_args != 1) {
19831978
zend_error(error_type, "Method %s::%s() must take exactly 1 argument", ZSTR_VAL(ce->name), ZEND_GET_FUNC_NAME);
19841979
} else if (QUICK_ARG_SHOULD_BE_SENT_BY_REF(fptr, 1)) {
19851980
zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ZSTR_VAL(ce->name), ZEND_GET_FUNC_NAME);
19861981
}
1987-
} else if (name_len == sizeof(ZEND_SET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME) - 1)) {
1982+
} else if (zend_string_equals_literal(lcname, ZEND_SET_FUNC_NAME)) {
19881983
if (fptr->common.num_args != 2) {
19891984
zend_error(error_type, "Method %s::%s() must take exactly 2 arguments", ZSTR_VAL(ce->name), ZEND_SET_FUNC_NAME);
19901985
} else if (QUICK_ARG_SHOULD_BE_SENT_BY_REF(fptr, 1) || QUICK_ARG_SHOULD_BE_SENT_BY_REF(fptr, 2)) {
19911986
zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ZSTR_VAL(ce->name), ZEND_SET_FUNC_NAME);
19921987
}
1993-
} else if (name_len == sizeof(ZEND_UNSET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_UNSET_FUNC_NAME, sizeof(ZEND_UNSET_FUNC_NAME) - 1)) {
1988+
} else if (zend_string_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) {
19941989
if (fptr->common.num_args != 1) {
19951990
zend_error(error_type, "Method %s::%s() must take exactly 1 argument", ZSTR_VAL(ce->name), ZEND_UNSET_FUNC_NAME);
19961991
} else if (QUICK_ARG_SHOULD_BE_SENT_BY_REF(fptr, 1)) {
19971992
zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ZSTR_VAL(ce->name), ZEND_UNSET_FUNC_NAME);
19981993
}
1999-
} else if (name_len == sizeof(ZEND_ISSET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_ISSET_FUNC_NAME, sizeof(ZEND_ISSET_FUNC_NAME) - 1)) {
1994+
} else if (zend_string_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) {
20001995
if (fptr->common.num_args != 1) {
20011996
zend_error(error_type, "Method %s::%s() must take exactly 1 argument", ZSTR_VAL(ce->name), ZEND_ISSET_FUNC_NAME);
20021997
} else if (QUICK_ARG_SHOULD_BE_SENT_BY_REF(fptr, 1)) {
20031998
zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ZSTR_VAL(ce->name), ZEND_ISSET_FUNC_NAME);
20041999
}
2005-
} else if (name_len == sizeof(ZEND_CALL_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME) - 1)) {
2000+
} else if (zend_string_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) {
20062001
if (fptr->common.num_args != 2) {
20072002
zend_error(error_type, "Method %s::%s() must take exactly 2 arguments", ZSTR_VAL(ce->name), ZEND_CALL_FUNC_NAME);
20082003
} else if (QUICK_ARG_SHOULD_BE_SENT_BY_REF(fptr, 1) || QUICK_ARG_SHOULD_BE_SENT_BY_REF(fptr, 2)) {
20092004
zend_error(error_type, "Method %s::%s() cannot take arguments by reference", ZSTR_VAL(ce->name), ZEND_CALL_FUNC_NAME);
20102005
}
2011-
} else if (name_len == sizeof(ZEND_CALLSTATIC_FUNC_NAME) - 1 &&
2012-
!memcmp(lcname, ZEND_CALLSTATIC_FUNC_NAME, sizeof(ZEND_CALLSTATIC_FUNC_NAME)-1)
2013-
) {
2006+
} else if (zend_string_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) {
20142007
if (fptr->common.num_args != 2) {
20152008
zend_error(error_type, "Method %s::__callStatic() must take exactly 2 arguments", ZSTR_VAL(ce->name));
20162009
} else if (QUICK_ARG_SHOULD_BE_SENT_BY_REF(fptr, 1) || QUICK_ARG_SHOULD_BE_SENT_BY_REF(fptr, 2)) {
20172010
zend_error(error_type, "Method %s::__callStatic() cannot take arguments by reference", ZSTR_VAL(ce->name));
20182011
}
2019-
} else if (name_len == sizeof(ZEND_TOSTRING_FUNC_NAME) - 1 &&
2020-
!memcmp(lcname, ZEND_TOSTRING_FUNC_NAME, sizeof(ZEND_TOSTRING_FUNC_NAME)-1) && fptr->common.num_args != 0
2021-
) {
2012+
} else if (zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME) && fptr->common.num_args != 0) {
20222013
zend_error(error_type, "Method %s::__toString() cannot take arguments", ZSTR_VAL(ce->name));
2023-
} else if (name_len == sizeof(ZEND_DEBUGINFO_FUNC_NAME) - 1 &&
2024-
!memcmp(lcname, ZEND_DEBUGINFO_FUNC_NAME, sizeof(ZEND_DEBUGINFO_FUNC_NAME)-1) && fptr->common.num_args != 0) {
2014+
} else if (zend_string_equals_literal(lcname, ZEND_DEBUGINFO_FUNC_NAME) && fptr->common.num_args != 0) {
20252015
zend_error(error_type, "Method %s::__debugInfo() cannot take arguments", ZSTR_VAL(ce->name));
2026-
} else if (
2027-
name_len == sizeof("__serialize") - 1
2028-
&& !memcmp(lcname, "__serialize", sizeof("__serialize") - 1)
2029-
&& fptr->common.num_args != 0
2030-
) {
2016+
} else if (zend_string_equals_literal(lcname, "__serialize") && fptr->common.num_args != 0) {
20312017
zend_error(error_type, "Method %s::__serialize() cannot take arguments", ZSTR_VAL(ce->name));
2032-
} else if (
2033-
name_len == sizeof("__unserialize") - 1
2034-
&& !memcmp(lcname, "__unserialize", sizeof("__unserialize") - 1)
2035-
&& fptr->common.num_args != 1
2036-
) {
2018+
} else if (zend_string_equals_literal(lcname, "__unserialize") && fptr->common.num_args != 1) {
20372019
zend_error(error_type, "Method %s::__unserialize() must take exactly 1 argument", ZSTR_VAL(ce->name));
20382020
}
2021+
2022+
zend_string_release_ex(lcname, 0);
20392023
}
20402024
/* }}} */
20412025

0 commit comments

Comments
 (0)