Skip to content

Commit fe4e278

Browse files
committed
Remove call to mbfl_strlen for reverse strrpos functions
1 parent 6be815b commit fe4e278

File tree

6 files changed

+26
-42
lines changed

6 files changed

+26
-42
lines changed

ext/mbstring/mbstring.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2158,15 +2158,6 @@ PHP_FUNCTION(mb_strrpos)
21582158
RETURN_THROWS();
21592159
}
21602160

2161-
if (offset != 0) {
2162-
size_t haystack_char_len = mbfl_strlen(&haystack);
2163-
if ((offset > 0 && offset > haystack_char_len) ||
2164-
(offset < 0 && -offset > haystack_char_len)) {
2165-
zend_value_error("Offset is greater than the length of haystack string");
2166-
RETURN_THROWS();
2167-
}
2168-
}
2169-
21702161
n = mbfl_strpos(&haystack, &needle, offset, 1);
21712162
if (!mbfl_is_error(n)) {
21722163
RETVAL_LONG(n);
@@ -4898,14 +4889,7 @@ MBSTRING_API size_t php_mb_stripos(int mode, const char *old_haystack, size_t ol
48984889
if (offset != 0) {
48994890
size_t haystack_char_len = mbfl_strlen(&haystack);
49004891

4901-
if (mode) {
4902-
if ((offset > 0 && (size_t)offset > haystack_char_len) ||
4903-
(offset < 0 && (size_t)(-offset) > haystack_char_len)) {
4904-
zend_value_error("Offset is greater than the length of haystack string");
4905-
n = -1;
4906-
break;
4907-
}
4908-
} else {
4892+
if (!mode) {
49094893
if (offset < 0) {
49104894
offset += (zend_long)haystack_char_len;
49114895
}

ext/mbstring/tests/bug43841.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ foreach ($offsets as $i) {
4848
--EXPECTF--
4949
-- Offset is -25 --
5050
Multibyte String:
51-
Offset is greater than the length of haystack string
51+
Offset not contained in string
5252
ASCII String:
5353
mb_strrpos:
54-
Offset is greater than the length of haystack string
54+
Offset not contained in string
5555
strrpos:
5656
Offset not contained in string
5757

5858
-- Offset is -24 --
5959
Multibyte String:
60-
Offset is greater than the length of haystack string
60+
Offset not contained in string
6161
ASCII String:
6262
mb_strrpos:
63-
Offset is greater than the length of haystack string
63+
Offset not contained in string
6464
strrpos:
6565
Offset not contained in string
6666

ext/mbstring/tests/bug45923.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ section('mb_strrpos' , "●○◆ ●○◆ ●○◆", "●○◆");
3030
section('strripos' , "abc abc abc" , "abc");
3131
section('mb_strripos', "●○◆ ●○◆ ●○◆", "●○◆");
3232
?>
33-
--EXPECTF--
33+
--EXPECT--
3434
------- strpos -----------
3535

3636
> Offset: 0
@@ -159,15 +159,15 @@ bool(false)
159159
> Offset: 11
160160
bool(false)
161161
> Offset: 12
162-
Offset is greater than the length of haystack string
162+
Offset not contained in string
163163
> Offset: -1
164164
int(8)
165165
> Offset: -3
166166
int(8)
167167
> Offset: -6
168168
int(4)
169169
> Offset: -20
170-
Offset is greater than the length of haystack string
170+
Offset not contained in string
171171

172172
------- strripos -----------
173173

@@ -205,12 +205,12 @@ bool(false)
205205
> Offset: 11
206206
bool(false)
207207
> Offset: 12
208-
Offset is greater than the length of haystack string
208+
Offset not contained in string
209209
> Offset: -1
210210
int(8)
211211
> Offset: -3
212212
int(8)
213213
> Offset: -6
214214
int(4)
215215
> Offset: -20
216-
Offset is greater than the length of haystack string
216+
Offset not contained in string

ext/mbstring/tests/mb_strripos_empty_needle.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ int(7)
7373
int(5)
7474

7575
-- ASCII string with out of bound positive offset --
76-
Offset is greater than the length of haystack string
76+
Offset not contained in string
7777

7878
-- ASCII string with out of bound negative offset --
79-
Offset is greater than the length of haystack string
79+
Offset not contained in string
8080

8181
-- Multi-byte string without offset --
8282
int(21)
@@ -88,7 +88,7 @@ int(21)
8888
int(19)
8989

9090
-- Multi-byte string with out of bound positive offset --
91-
Offset is greater than the length of haystack string
91+
Offset not contained in string
9292

9393
-- Multi-byte string with out of bound negative offset --
94-
Offset is greater than the length of haystack string
94+
Offset not contained in string

ext/mbstring/tests/mb_strripos_variation5_Bug45923.phpt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,24 @@ int(20)
8181

8282
**-- Offset is: 30 --**
8383
-- ASCII String --
84-
Offset is greater than the length of haystack string
84+
Offset not contained in string
8585
--Multibyte String --
86-
Offset is greater than the length of haystack string
86+
Offset not contained in string
8787

8888
**-- Offset is: 40 --**
8989
-- ASCII String --
90-
Offset is greater than the length of haystack string
90+
Offset not contained in string
9191
--Multibyte String --
92-
Offset is greater than the length of haystack string
92+
Offset not contained in string
9393

9494
**-- Offset is: 50 --**
9595
-- ASCII String --
96-
Offset is greater than the length of haystack string
96+
Offset not contained in string
9797
--Multibyte String --
98-
Offset is greater than the length of haystack string
98+
Offset not contained in string
9999

100100
**-- Offset is: 60 --**
101101
-- ASCII String --
102-
Offset is greater than the length of haystack string
102+
Offset not contained in string
103103
--Multibyte String --
104-
Offset is greater than the length of haystack string
104+
Offset not contained in string

ext/mbstring/tests/mb_strrpos_empty_needle.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ int(7)
7373
int(5)
7474

7575
-- ASCII string with out of bound positive offset --
76-
Offset is greater than the length of haystack string
76+
Offset not contained in string
7777

7878
-- ASCII string with out of bound negative offset --
79-
Offset is greater than the length of haystack string
79+
Offset not contained in string
8080

8181
-- Multi-byte string without offset --
8282
int(21)
@@ -88,7 +88,7 @@ int(21)
8888
int(19)
8989

9090
-- Multi-byte string with out of bound positive offset --
91-
Offset is greater than the length of haystack string
91+
Offset not contained in string
9292

9393
-- Multi-byte string with out of bound negative offset --
94-
Offset is greater than the length of haystack string
94+
Offset not contained in string

0 commit comments

Comments
 (0)