Skip to content

Commit 5e7aa47

Browse files
committed
Remove mbfl_strlen call when offset is positive in strpos functions
1 parent fe4e278 commit 5e7aa47

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

ext/mbstring/mbstring.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2100,12 +2100,10 @@ PHP_FUNCTION(mb_strpos)
21002100
RETURN_THROWS();
21012101
}
21022102

2103-
if (offset != 0) {
2103+
if (offset < 0) {
21042104
size_t slen = mbfl_strlen(&haystack);
2105+
offset += slen;
21052106
if (offset < 0) {
2106-
offset += slen;
2107-
}
2108-
if (offset < 0 || offset > slen) {
21092107
zend_value_error("Offset not contained in string");
21102108
RETURN_THROWS();
21112109
}
@@ -4886,18 +4884,12 @@ MBSTRING_API size_t php_mb_stripos(int mode, const char *old_haystack, size_t ol
48864884
break;
48874885
}
48884886

4889-
if (offset != 0) {
4887+
if (offset < 0 && !mode) {
48904888
size_t haystack_char_len = mbfl_strlen(&haystack);
4891-
4892-
if (!mode) {
4893-
if (offset < 0) {
4894-
offset += (zend_long)haystack_char_len;
4895-
}
4896-
if (offset < 0 || (size_t)offset > haystack_char_len) {
4897-
zend_value_error("Offset not contained in string");
4898-
n = -1;
4899-
break;
4900-
}
4889+
offset += (zend_long)haystack_char_len;
4890+
if (offset < 0) {
4891+
n = -16;
4892+
break;
49014893
}
49024894
}
49034895

0 commit comments

Comments
 (0)