Skip to content

Commit b11b261

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 2f65895 commit b11b261

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
@@ -268,15 +268,7 @@ static const mbfl_encoding *php_mb_get_encoding(zend_string *encoding_name, uint
268268
}
269269
}
270270

271-
static const mbfl_encoding *php_mb_get_encoding_or_pass(const char *encoding_name) {
272-
if (strcmp(encoding_name, "pass") == 0) {
273-
return &mbfl_encoding_pass;
274-
}
275-
276-
return mbfl_name2encoding(encoding_name);
277-
}
278-
279-
static const mbfl_encoding *php_mb_get_encoding_or_pass_ex(const char *encoding_name, size_t encoding_name_len) {
271+
static const mbfl_encoding *php_mb_get_encoding_or_pass(const char *encoding_name, size_t encoding_name_len) {
280272
if (strncmp(encoding_name, "pass", encoding_name_len) == 0) {
281273
return &mbfl_encoding_pass;
282274
}
@@ -351,7 +343,7 @@ static zend_result php_mb_parse_encoding_list(const char *value, size_t value_le
351343
}
352344
} else {
353345
const mbfl_encoding *encoding =
354-
allow_pass_encoding ? php_mb_get_encoding_or_pass_ex(p1, p1_length) : mbfl_name2encoding_ex(p1, p1_length);
346+
allow_pass_encoding ? php_mb_get_encoding_or_pass(p1, p1_length) : mbfl_name2encoding_ex(p1, p1_length);
355347
if (!encoding) {
356348
/* Called from an INI setting modification */
357349
if (arg_num == 0) {
@@ -762,7 +754,7 @@ static PHP_INI_MH(OnUpdate_mbstring_http_input)
762754
/* }}} */
763755

764756
static zend_result _php_mb_ini_mbstring_http_output_set(const char *new_value, size_t length) {
765-
const mbfl_encoding *encoding = php_mb_get_encoding_or_pass(new_value);
757+
const mbfl_encoding *encoding = php_mb_get_encoding_or_pass(new_value, length);
766758
if (!encoding) {
767759
return FAILURE;
768760
}
@@ -1346,7 +1338,7 @@ PHP_FUNCTION(mb_http_output)
13461338
ZEND_ASSERT(MBSTRG(current_http_output_encoding));
13471339
RETURN_STRING(MBSTRG(current_http_output_encoding)->name);
13481340
} else {
1349-
const mbfl_encoding *encoding = php_mb_get_encoding_or_pass(name);
1341+
const mbfl_encoding *encoding = php_mb_get_encoding_or_pass(name, name_len);
13501342
if (!encoding) {
13511343
zend_argument_value_error(1, "must be a valid encoding, \"%s\" given", name);
13521344
RETURN_THROWS();

0 commit comments

Comments
 (0)