1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Return early from mb_get_substr if 'len' parameter is zero

This internal function is used to implement mb_strstr, mb_stristr,
mb_strrchr, mb_strrichr, mb_substr, mb_strimwidth, mb_trim, and
mb_str_pad. All of these functions will be faster if we return
early when requested for a zero-length "substring".
This commit is contained in:
Alex Dowad
2023-12-05 21:04:37 +02:00
parent 56077b03d5
commit a2ea45211c

View File

@@ -2108,7 +2108,7 @@ static zend_string* mb_get_substr(zend_string *input, size_t from, size_t len, c
unsigned char *in = (unsigned char*)ZSTR_VAL(input);
size_t in_len = ZSTR_LEN(input);
if (from >= in_len) {
if (from >= in_len || len == 0) {
/* No supported text encoding decodes to more than one codepoint per byte
* So if the number of codepoints to skip >= number of input bytes,
* then definitely the output should be empty */