Skip to content

Commit 484873c

Browse files
committed
Use strlen(str) instead of sizeof(str)-1
1 parent 414f7fc commit 484873c

File tree

178 files changed

+1802
-1802
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

178 files changed

+1802
-1802
lines changed

Zend/Optimizer/block_pass.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
334334
zval *arg = &OPLINE_OP1_LITERAL(sv);
335335
char *fname = FUNCTION_CACHE->funcs[Z_LVAL(ZEND_OP1_LITERAL(fcall))].function_name;
336336
size_t flen = FUNCTION_CACHE->funcs[Z_LVAL(ZEND_OP1_LITERAL(fcall))].name_len;
337-
if((flen == sizeof("function_exists")-1 && zend_binary_strcasecmp(fname, flen, "function_exists", sizeof("function_exists")-1) == 0) ||
338-
(flen == sizeof("is_callable")-1 && zend_binary_strcasecmp(fname, flen, "is_callable", sizeof("is_callable")-1) == 0)
337+
if((flen == strlen("function_exists") && zend_binary_strcasecmp(fname, flen, "function_exists", strlen("function_exists")) == 0) ||
338+
(flen == strlen("is_callable") && zend_binary_strcasecmp(fname, flen, "is_callable", strlen("is_callable")) == 0)
339339
) {
340340
zend_function *function;
341341
if((function = zend_hash_find_ptr(EG(function_table), Z_STR_P(arg))) != NULL) {
@@ -345,7 +345,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
345345
LITERAL_BOOL(opline->op1, 1);
346346
opline->op1_type = IS_CONST;
347347
}
348-
} else if(flen == sizeof("constant")-1 && zend_binary_strcasecmp(fname, flen, "constant", sizeof("constant")-1) == 0) {
348+
} else if(flen == strlen("constant") && zend_binary_strcasecmp(fname, flen, "constant", strlen("constant")) == 0) {
349349
zval c;
350350
if (zend_optimizer_get_persistent_constant(Z_STR_P(arg), &c, 1 ELS_CC)) {
351351
literal_dtor(arg);
@@ -355,7 +355,7 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
355355
/* no copy ctor - get already copied it */
356356
opline->op1_type = IS_CONST;
357357
}
358-
} else if(flen == sizeof("extension_loaded")-1 && zend_binary_strcasecmp(fname, flen, "extension_loaded", sizeof("extension_loaded")-1) == 0) {
358+
} else if(flen == strlen("extension_loaded") && zend_binary_strcasecmp(fname, flen, "extension_loaded", strlen("extension_loaded")) == 0) {
359359
if(zend_hash_exists(&module_registry, Z_STR_P(arg))) {
360360
literal_dtor(arg);
361361
MAKE_NOP(sv);

Zend/Optimizer/pass1.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
131131
memset(&fake_execute_data, 0, sizeof(zend_execute_data));
132132
fake_execute_data.func = (zend_function*)op_array;
133133
EG(current_execute_data) = &fake_execute_data;
134-
if ((offset = zend_get_constant_str("__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__") - 1)) != NULL) {
134+
if ((offset = zend_get_constant_str("__COMPILER_HALT_OFFSET__", strlen("__COMPILER_HALT_OFFSET__"))) != NULL) {
135135

136136
literal_dtor(&ZEND_OP2_LITERAL(opline));
137137
replace_by_const_or_qm_assign(op_array, opline, offset);
@@ -232,7 +232,7 @@ void zend_optimizer_pass1(zend_op_array *op_array, zend_optimizer_ctx *ctx)
232232
}
233233

234234
if (RESULT_UNUSED(opline) &&
235-
!zend_memnstr(Z_STRVAL(ZEND_OP1_LITERAL(send1_opline)), "::", sizeof("::") - 1, Z_STRVAL(ZEND_OP1_LITERAL(send1_opline)) + Z_STRLEN(ZEND_OP1_LITERAL(send1_opline)))) {
235+
!zend_memnstr(Z_STRVAL(ZEND_OP1_LITERAL(send1_opline)), "::", strlen("::"), Z_STRVAL(ZEND_OP1_LITERAL(send1_opline)) + Z_STRLEN(ZEND_OP1_LITERAL(send1_opline)))) {
236236

237237
opline->opcode = ZEND_DECLARE_CONST;
238238
opline->op1_type = IS_CONST;

Zend/zend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ void zend_startup(zend_utility_functions *utility_functions) /* {{{ */
990990
zend_interned_strings_init();
991991
zend_startup_builtin_functions();
992992
zend_register_standard_constants();
993-
zend_register_auto_global(zend_string_init_interned("GLOBALS", sizeof("GLOBALS") - 1, 1), 1, php_auto_globals_create_globals);
993+
zend_register_auto_global(zend_string_init_interned("GLOBALS", strlen("GLOBALS"), 1), 1, php_auto_globals_create_globals);
994994

995995
#ifndef ZTS
996996
zend_init_rsrc_plist();

Zend/zend_API.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3738,7 +3738,7 @@ ZEND_API zend_string *zend_get_callable_name_ex(zval *callable, zend_object *obj
37383738
zend_class_entry *ce = Z_OBJCE_P(callable);
37393739
return zend_string_concat2(
37403740
ZSTR_VAL(ce->name), ZSTR_LEN(ce->name),
3741-
"::__invoke", sizeof("::__invoke") - 1);
3741+
"::__invoke", strlen("::__invoke"));
37423742
}
37433743
case IS_REFERENCE:
37443744
callable = Z_REFVAL_P(callable);
@@ -4832,7 +4832,7 @@ static zend_result get_default_via_ast(zval *default_value_zval, const char *def
48324832
zend_arena *ast_arena;
48334833

48344834
zend_string *code = zend_string_concat3(
4835-
"<?php ", sizeof("<?php ") - 1, default_value, strlen(default_value), ";", 1);
4835+
"<?php ", strlen("<?php "), default_value, strlen(default_value), ";", 1);
48364836

48374837
ast = zend_compile_string_to_ast(code, &ast_arena, ZSTR_EMPTY_ALLOC());
48384838
zend_string_release(code);
@@ -4886,16 +4886,16 @@ ZEND_API zend_result zend_get_default_from_internal_arg_info(
48864886
/* Avoid going through the full AST machinery for some simple and common cases. */
48874887
size_t default_value_len = strlen(default_value);
48884888
zend_ulong lval;
4889-
if (default_value_len == sizeof("null")-1
4890-
&& !memcmp(default_value, "null", sizeof("null")-1)) {
4889+
if (default_value_len == strlen("null")
4890+
&& !memcmp(default_value, "null", strlen("null"))) {
48914891
ZVAL_NULL(default_value_zval);
48924892
return SUCCESS;
4893-
} else if (default_value_len == sizeof("true")-1
4894-
&& !memcmp(default_value, "true", sizeof("true")-1)) {
4893+
} else if (default_value_len == strlen("true")
4894+
&& !memcmp(default_value, "true", strlen("true"))) {
48954895
ZVAL_TRUE(default_value_zval);
48964896
return SUCCESS;
4897-
} else if (default_value_len == sizeof("false")-1
4898-
&& !memcmp(default_value, "false", sizeof("false")-1)) {
4897+
} else if (default_value_len == strlen("false")
4898+
&& !memcmp(default_value, "false", strlen("false"))) {
48994899
ZVAL_FALSE(default_value_zval);
49004900
return SUCCESS;
49014901
} else if (default_value_len >= 2
@@ -4907,8 +4907,8 @@ ZEND_API zend_result zend_get_default_from_internal_arg_info(
49074907
ZVAL_STR(default_value_zval, str);
49084908
return SUCCESS;
49094909
}
4910-
} else if (default_value_len == sizeof("[]")-1
4911-
&& !memcmp(default_value, "[]", sizeof("[]")-1)) {
4910+
} else if (default_value_len == strlen("[]")
4911+
&& !memcmp(default_value, "[]", strlen("[]"))) {
49124912
ZVAL_EMPTY_ARRAY(default_value_zval);
49134913
return SUCCESS;
49144914
} else if (ZEND_HANDLE_NUMERIC_STR(default_value, default_value_len, lval)) {

Zend/zend_ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1631,7 +1631,7 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
16311631
break;
16321632
}
16331633
case ZEND_AST_CONSTANT_CLASS:
1634-
smart_str_appendl(str, "__CLASS__", sizeof("__CLASS__")-1);
1634+
smart_str_appendl(str, "__CLASS__", strlen("__CLASS__"));
16351635
break;
16361636
case ZEND_AST_ZNODE:
16371637
/* This AST kind is only used for temporary nodes during compilation */

Zend/zend_attributes_arginfo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static zend_class_entry *register_class_Attribute(void)
7373

7474
zval property_flags_default_value;
7575
ZVAL_UNDEF(&property_flags_default_value);
76-
zend_string *property_flags_name = zend_string_init("flags", sizeof("flags") - 1, 1);
76+
zend_string *property_flags_name = zend_string_init("flags", strlen("flags"), 1);
7777
zend_declare_typed_property(class_entry, property_flags_name, &property_flags_default_value, ZEND_ACC_PUBLIC, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_LONG));
7878
zend_string_release(property_flags_name);
7979

@@ -123,7 +123,7 @@ static zend_class_entry *register_class_SensitiveParameterValue(void)
123123

124124
zval property_value_default_value;
125125
ZVAL_UNDEF(&property_value_default_value);
126-
zend_string *property_value_name = zend_string_init("value", sizeof("value") - 1, 1);
126+
zend_string *property_value_name = zend_string_init("value", strlen("value"), 1);
127127
zend_declare_typed_property(class_entry, property_value_name, &property_value_default_value, ZEND_ACC_PRIVATE|ZEND_ACC_READONLY, NULL, (zend_type) ZEND_TYPE_INIT_MASK(MAY_BE_ANY));
128128
zend_string_release(property_value_name);
129129

Zend/zend_builtin_functions.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ ZEND_FUNCTION(gc_enable)
112112

113113
ZEND_PARSE_PARAMETERS_NONE();
114114

115-
key = zend_string_init("zend.enable_gc", sizeof("zend.enable_gc")-1, 0);
116-
zend_alter_ini_entry_chars(key, "1", sizeof("1")-1, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME);
115+
key = zend_string_init("zend.enable_gc", strlen("zend.enable_gc"), 0);
116+
zend_alter_ini_entry_chars(key, "1", strlen("1"), ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME);
117117
zend_string_release_ex(key, 0);
118118
}
119119
/* }}} */
@@ -125,8 +125,8 @@ ZEND_FUNCTION(gc_disable)
125125

126126
ZEND_PARSE_PARAMETERS_NONE();
127127

128-
key = zend_string_init("zend.enable_gc", sizeof("zend.enable_gc")-1, 0);
129-
zend_alter_ini_entry_chars(key, "0", sizeof("0")-1, ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME);
128+
key = zend_string_init("zend.enable_gc", strlen("zend.enable_gc"), 0);
129+
zend_alter_ini_entry_chars(key, "0", strlen("0"), ZEND_INI_USER, ZEND_INI_STAGE_RUNTIME);
130130
zend_string_release_ex(key, 0);
131131
}
132132
/* }}} */
@@ -142,10 +142,10 @@ ZEND_FUNCTION(gc_status)
142142

143143
array_init_size(return_value, 3);
144144

145-
add_assoc_long_ex(return_value, "runs", sizeof("runs")-1, (long)status.runs);
146-
add_assoc_long_ex(return_value, "collected", sizeof("collected")-1, (long)status.collected);
147-
add_assoc_long_ex(return_value, "threshold", sizeof("threshold")-1, (long)status.threshold);
148-
add_assoc_long_ex(return_value, "roots", sizeof("roots")-1, (long)status.num_roots);
145+
add_assoc_long_ex(return_value, "runs", strlen("runs"), (long)status.runs);
146+
add_assoc_long_ex(return_value, "collected", strlen("collected"), (long)status.collected);
147+
add_assoc_long_ex(return_value, "threshold", strlen("threshold"), (long)status.threshold);
148+
add_assoc_long_ex(return_value, "roots", strlen("roots"), (long)status.num_roots);
149149
}
150150
/* }}} */
151151

@@ -481,7 +481,7 @@ ZEND_FUNCTION(define)
481481
Z_PARAM_BOOL(non_cs)
482482
ZEND_PARSE_PARAMETERS_END();
483483

484-
if (zend_memnstr(ZSTR_VAL(name), "::", sizeof("::") - 1, ZSTR_VAL(name) + ZSTR_LEN(name))) {
484+
if (zend_memnstr(ZSTR_VAL(name), "::", strlen("::"), ZSTR_VAL(name) + ZSTR_LEN(name))) {
485485
zend_argument_value_error(1, "cannot be a class constant");
486486
RETURN_THROWS();
487487
}
@@ -1323,8 +1323,8 @@ ZEND_FUNCTION(get_defined_functions)
13231323
}
13241324
} ZEND_HASH_FOREACH_END();
13251325

1326-
zend_hash_str_add_new(Z_ARRVAL_P(return_value), "internal", sizeof("internal")-1, &internal);
1327-
zend_hash_str_add_new(Z_ARRVAL_P(return_value), "user", sizeof("user")-1, &user);
1326+
zend_hash_str_add_new(Z_ARRVAL_P(return_value), "internal", strlen("internal"), &internal);
1327+
zend_hash_str_add_new(Z_ARRVAL_P(return_value), "user", strlen("user"), &user);
13281328
}
13291329
/* }}} */
13301330

@@ -1563,7 +1563,7 @@ static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) /
15631563
zend_attribute *attribute = zend_get_parameter_attribute_str(
15641564
call->func->common.attributes,
15651565
"sensitiveparameter",
1566-
sizeof("sensitiveparameter") - 1,
1566+
strlen("sensitiveparameter"),
15671567
i
15681568
);
15691569

@@ -1595,7 +1595,7 @@ static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) /
15951595
zend_attribute *attribute = zend_get_parameter_attribute_str(
15961596
call->func->common.attributes,
15971597
"sensitiveparameter",
1598-
sizeof("sensitiveparameter") - 1,
1598+
strlen("sensitiveparameter"),
15991599
i
16001600
);
16011601
bool is_sensitive = attribute != NULL;
@@ -1634,7 +1634,7 @@ static void debug_backtrace_get_args(zend_execute_data *call, zval *arg_array) /
16341634
zend_attribute *attribute = zend_get_parameter_attribute_str(
16351635
call->func->common.attributes,
16361636
"sensitiveparameter",
1637-
sizeof("sensitiveparameter") - 1,
1637+
strlen("sensitiveparameter"),
16381638
MIN(i, call->func->common.num_args)
16391639
);
16401640
is_sensitive = attribute != NULL;
@@ -1953,7 +1953,7 @@ ZEND_FUNCTION(get_extension_funcs)
19531953
module = zend_hash_find_ptr(&module_registry, lcname);
19541954
zend_string_release_ex(lcname, 0);
19551955
} else {
1956-
module = zend_hash_str_find_ptr(&module_registry, "core", sizeof("core") - 1);
1956+
module = zend_hash_str_find_ptr(&module_registry, "core", strlen("core"));
19571957
}
19581958

19591959
if (!module) {

Zend/zend_closures.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ static HashTable *zend_closure_get_debug_info(zend_object *object, int *is_temp)
616616
zend_string_release_ex(name, 0);
617617
arg_info++;
618618
}
619-
zend_hash_str_update(debug_info, "parameter", sizeof("parameter")-1, &val);
619+
zend_hash_str_update(debug_info, "parameter", strlen("parameter"), &val);
620620
}
621621

622622
return debug_info;

Zend/zend_compile.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ uint32_t zend_add_member_modifier(uint32_t flags, uint32_t new_flag) /* {{{ */
843843
ZEND_API zend_string *zend_create_member_string(zend_string *class_name, zend_string *member_name) {
844844
return zend_string_concat3(
845845
ZSTR_VAL(class_name), ZSTR_LEN(class_name),
846-
"::", sizeof("::") - 1,
846+
"::", strlen("::"),
847847
ZSTR_VAL(member_name), ZSTR_LEN(member_name));
848848
}
849849

@@ -1852,7 +1852,7 @@ zend_ast *zend_negate_num_string(zend_ast *ast) /* {{{ */
18521852
zval *zv = zend_ast_get_zval(ast);
18531853
if (Z_TYPE_P(zv) == IS_LONG) {
18541854
if (Z_LVAL_P(zv) == 0) {
1855-
ZVAL_NEW_STR(zv, zend_string_init("-0", sizeof("-0")-1, 0));
1855+
ZVAL_NEW_STR(zv, zend_string_init("-0", strlen("-0"), 0));
18561856
} else {
18571857
ZEND_ASSERT(Z_LVAL_P(zv) > 0);
18581858
Z_LVAL_P(zv) *= -1;
@@ -4033,7 +4033,7 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
40334033
/* If the original argument was named, add the new argument as named as well,
40344034
* as mixing named and positional is not allowed. */
40354035
zend_ast *name = zend_ast_create_zval_from_str(
4036-
zend_string_init("description", sizeof("description") - 1, 0));
4036+
zend_string_init("description", strlen("description"), 0));
40374037
arg = zend_ast_create(ZEND_AST_NAMED_ARG, name, arg);
40384038
}
40394039
zend_ast_list_add((zend_ast *) args, arg);
@@ -6963,9 +6963,9 @@ static void add_stringable_interface(zend_class_entry *ce) {
69636963
erealloc(ce->interface_names, sizeof(zend_class_name) * ce->num_interfaces);
69646964
// TODO: Add known interned strings instead?
69656965
ce->interface_names[ce->num_interfaces - 1].name =
6966-
zend_string_init("Stringable", sizeof("Stringable") - 1, 0);
6966+
zend_string_init("Stringable", strlen("Stringable"), 0);
69676967
ce->interface_names[ce->num_interfaces - 1].lc_name =
6968-
zend_string_init("stringable", sizeof("stringable") - 1, 0);
6968+
zend_string_init("stringable", strlen("stringable"), 0);
69696969
}
69706970

69716971
static zend_string *zend_begin_method_decl(zend_op_array *op_array, zend_string *name, bool has_body) /* {{{ */

Zend/zend_constants.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,9 @@ void zend_register_standard_constants(void)
136136
REGISTER_MAIN_BOOL_CONSTANT("FALSE", 0, CONST_PERSISTENT);
137137
REGISTER_MAIN_NULL_CONSTANT("NULL", CONST_PERSISTENT);
138138

139-
true_const = zend_hash_str_find_ptr(EG(zend_constants), "TRUE", sizeof("TRUE")-1);
140-
false_const = zend_hash_str_find_ptr(EG(zend_constants), "FALSE", sizeof("FALSE")-1);
141-
null_const = zend_hash_str_find_ptr(EG(zend_constants), "NULL", sizeof("NULL")-1);
139+
true_const = zend_hash_str_find_ptr(EG(zend_constants), "TRUE", strlen("TRUE"));
140+
false_const = zend_hash_str_find_ptr(EG(zend_constants), "FALSE", strlen("FALSE"));
141+
null_const = zend_hash_str_find_ptr(EG(zend_constants), "NULL", strlen("NULL"));
142142
}
143143

144144

@@ -213,8 +213,8 @@ static zend_constant *zend_get_halt_offset_constant(const char *name, size_t nam
213213

214214
if (!EG(current_execute_data)) {
215215
return NULL;
216-
} else if (name_len == sizeof("__COMPILER_HALT_OFFSET__")-1 &&
217-
!memcmp(name, "__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__")-1)) {
216+
} else if (name_len == strlen("__COMPILER_HALT_OFFSET__") &&
217+
!memcmp(name, "__COMPILER_HALT_OFFSET__", strlen("__COMPILER_HALT_OFFSET__"))) {
218218
const char *cfilename;
219219
zend_string *haltname;
220220
size_t clen;
@@ -223,7 +223,7 @@ static zend_constant *zend_get_halt_offset_constant(const char *name, size_t nam
223223
clen = strlen(cfilename);
224224
/* check for __COMPILER_HALT_OFFSET__ */
225225
haltname = zend_mangle_property_name(haltoff,
226-
sizeof("__COMPILER_HALT_OFFSET__") - 1, cfilename, clen, 0);
226+
strlen("__COMPILER_HALT_OFFSET__"), cfilename, clen, 0);
227227
c = zend_hash_find_ptr(EG(zend_constants), haltname);
228228
zend_string_efree(haltname);
229229
return c;

Zend/zend_enum.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ void zend_enum_add_interfaces(zend_class_entry *ce)
175175
ce->interface_names = erealloc(ce->interface_names, sizeof(zend_class_name) * ce->num_interfaces);
176176

177177
ce->interface_names[num_interfaces_before].name = zend_string_copy(zend_ce_unit_enum->name);
178-
ce->interface_names[num_interfaces_before].lc_name = zend_string_init("unitenum", sizeof("unitenum") - 1, 0);
178+
ce->interface_names[num_interfaces_before].lc_name = zend_string_init("unitenum", strlen("unitenum"), 0);
179179

180180
if (ce->enum_backing_type != IS_UNDEF) {
181181
ce->interface_names[num_interfaces_before + 1].name = zend_string_copy(zend_ce_backed_enum->name);
182-
ce->interface_names[num_interfaces_before + 1].lc_name = zend_string_init("backedenum", sizeof("backedenum") - 1, 0);
182+
ce->interface_names[num_interfaces_before + 1].lc_name = zend_string_init("backedenum", strlen("backedenum"), 0);
183183
}
184184
}
185185

Zend/zend_exceptions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ ZEND_METHOD(Exception, __toString)
660660
str = ZSTR_EMPTY_ALLOC();
661661

662662
exception = ZEND_THIS;
663-
fname = zend_string_init("gettraceasstring", sizeof("gettraceasstring")-1, 0);
663+
fname = zend_string_init("gettraceasstring", strlen("gettraceasstring"), 0);
664664

665665
while (exception && Z_TYPE_P(exception) == IS_OBJECT && instanceof_function(Z_OBJCE_P(exception), zend_ce_throwable)) {
666666
zend_string *prev_str = str;

0 commit comments

Comments
 (0)