Skip to content

Commit 4e49c1d

Browse files
committed
ext/mbstring: Always pass length to php_mb_get_encoding_or_pass()
We have access to this information, so propagate it instead of calling strlen(). This also removes the newly introduced _ex() variant.
1 parent e00b3a1 commit 4e49c1d

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

ext/mbstring/mbstring.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,7 @@ static const mbfl_encoding *php_mb_get_encoding(zend_string *encoding_name, uint
269269
}
270270
}
271271

272-
static const mbfl_encoding *php_mb_get_encoding_or_pass(const char *encoding_name) {
273-
if (strcmp(encoding_name, "pass") == 0) {
274-
return &mbfl_encoding_pass;
275-
}
276-
277-
return mbfl_name2encoding(encoding_name);
278-
}
279-
280-
static const mbfl_encoding *php_mb_get_encoding_or_pass_ex(const char *encoding_name, size_t encoding_name_len) {
272+
static const mbfl_encoding *php_mb_get_encoding_or_pass(const char *encoding_name, size_t encoding_name_len) {
281273
if (strncmp(encoding_name, "pass", encoding_name_len) == 0) {
282274
return &mbfl_encoding_pass;
283275
}
@@ -352,7 +344,7 @@ static zend_result php_mb_parse_encoding_list(const char *value, size_t value_le
352344
}
353345
} else {
354346
const mbfl_encoding *encoding =
355-
allow_pass_encoding ? php_mb_get_encoding_or_pass_ex(p1, p1_length) : mbfl_name2encoding_ex(p1, p1_length);
347+
allow_pass_encoding ? php_mb_get_encoding_or_pass(p1, p1_length) : mbfl_name2encoding_ex(p1, p1_length);
356348
if (!encoding) {
357349
/* Called from an INI setting modification */
358350
if (arg_num == 0) {
@@ -763,7 +755,7 @@ static PHP_INI_MH(OnUpdate_mbstring_http_input)
763755
/* }}} */
764756

765757
static zend_result _php_mb_ini_mbstring_http_output_set(const char *new_value, size_t length) {
766-
const mbfl_encoding *encoding = php_mb_get_encoding_or_pass(new_value);
758+
const mbfl_encoding *encoding = php_mb_get_encoding_or_pass(new_value, length);
767759
if (!encoding) {
768760
return FAILURE;
769761
}
@@ -1350,7 +1342,7 @@ PHP_FUNCTION(mb_http_output)
13501342
ZEND_ASSERT(MBSTRG(current_http_output_encoding));
13511343
RETURN_STRING(MBSTRG(current_http_output_encoding)->name);
13521344
} else {
1353-
const mbfl_encoding *encoding = php_mb_get_encoding_or_pass(name);
1345+
const mbfl_encoding *encoding = php_mb_get_encoding_or_pass(name, name_len);
13541346
if (!encoding) {
13551347
zend_argument_value_error(1, "must be a valid encoding, \"%s\" given", name);
13561348
RETURN_THROWS();

0 commit comments

Comments
 (0)