Skip to content

Commit e1491f6

Browse files
committed
Remove call to mbfl_strlen for reverse strrpos functions
1 parent 9523b8c commit e1491f6

File tree

6 files changed

+26
-90
lines changed

6 files changed

+26
-90
lines changed

ext/mbstring/mbstring.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,15 +2155,6 @@ PHP_FUNCTION(mb_strrpos)
21552155
RETURN_FALSE;
21562156
}
21572157

2158-
if (offset != 0) {
2159-
size_t haystack_char_len = mbfl_strlen(&haystack);
2160-
if ((offset > 0 && offset > haystack_char_len) ||
2161-
(offset < 0 && -offset > haystack_char_len)) {
2162-
php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string");
2163-
RETURN_FALSE;
2164-
}
2165-
}
2166-
21672158
n = mbfl_strpos(&haystack, &needle, offset, 1);
21682159
if (!mbfl_is_error(n)) {
21692160
RETVAL_LONG(n);
@@ -4888,13 +4879,7 @@ MBSTRING_API size_t php_mb_stripos(int mode, const char *old_haystack, size_t ol
48884879
if (offset != 0) {
48894880
size_t haystack_char_len = mbfl_strlen(&haystack);
48904881

4891-
if (mode) {
4892-
if ((offset > 0 && (size_t)offset > haystack_char_len) ||
4893-
(offset < 0 && (size_t)(-offset) > haystack_char_len)) {
4894-
php_error_docref(NULL, E_WARNING, "Offset is greater than the length of haystack string");
4895-
break;
4896-
}
4897-
} else {
4882+
if (!mode) {
48984883
if (offset < 0) {
48994884
offset += (zend_long)haystack_char_len;
49004885
}

ext/mbstring/tests/bug43841.phpt

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,19 @@ foreach ($offsets as $i) {
4747
--EXPECTF--
4848
-- Offset is -25 --
4949
Multibyte String:
50-
51-
Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
52-
bool(false)
50+
Offset not contained in string
5351
ASCII String:
5452
mb_strrpos:
55-
56-
Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
57-
bool(false)
53+
Offset not contained in string
5854
strrpos:
5955
Offset not contained in string
6056

6157
-- Offset is -24 --
6258
Multibyte String:
63-
64-
Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
65-
bool(false)
59+
Offset not contained in string
6660
ASCII String:
6761
mb_strrpos:
68-
69-
Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
70-
bool(false)
62+
Offset not contained in string
7163
strrpos:
7264
Offset not contained in string
7365

ext/mbstring/tests/bug45923.phpt

Lines changed: 5 additions & 13 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,19 +159,15 @@ bool(false)
159159
> Offset: 11
160160
bool(false)
161161
> Offset: 12
162-
163-
Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
164-
bool(false)
162+
Offset not contained in string
165163
> Offset: -1
166164
int(8)
167165
> Offset: -3
168166
int(8)
169167
> Offset: -6
170168
int(4)
171169
> Offset: -20
172-
173-
Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
174-
bool(false)
170+
Offset not contained in string
175171

176172
------- strripos -----------
177173

@@ -209,16 +205,12 @@ bool(false)
209205
> Offset: 11
210206
bool(false)
211207
> Offset: 12
212-
213-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
214-
bool(false)
208+
Offset not contained in string
215209
> Offset: -1
216210
int(8)
217211
> Offset: -3
218212
int(8)
219213
> Offset: -6
220214
int(4)
221215
> Offset: -20
222-
223-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
224-
bool(false)
216+
Offset not contained in string

ext/mbstring/tests/mb_strripos_empty_needle.phpt

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

7575
-- ASCII string with out of bound positive offset --
76-
77-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
78-
bool(false)
76+
Offset not contained in string
7977

8078
-- ASCII string with out of bound negative offset --
81-
82-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
83-
bool(false)
79+
Offset not contained in string
8480

8581
-- Multi-byte string without offset --
8682
int(21)
@@ -92,11 +88,7 @@ int(21)
9288
int(19)
9389

9490
-- Multi-byte string with out of bound positive offset --
95-
96-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
97-
bool(false)
91+
Offset not contained in string
9892

9993
-- Multi-byte string with out of bound negative offset --
100-
101-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
102-
bool(false)
94+
Offset not contained in string

ext/mbstring/tests/mb_strripos_variation5_Bug45923.phpt

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

8282
**-- Offset is: 30 --**
8383
-- ASCII String --
84-
85-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
86-
bool(false)
84+
Offset not contained in string
8785
--Multibyte String --
88-
89-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
90-
bool(false)
86+
Offset not contained in string
9187

9288
**-- Offset is: 40 --**
9389
-- ASCII String --
94-
95-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
96-
bool(false)
90+
Offset not contained in string
9791
--Multibyte String --
98-
99-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
100-
bool(false)
92+
Offset not contained in string
10193

10294
**-- Offset is: 50 --**
10395
-- ASCII String --
104-
105-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
106-
bool(false)
96+
Offset not contained in string
10797
--Multibyte String --
108-
109-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
110-
bool(false)
98+
Offset not contained in string
11199

112100
**-- Offset is: 60 --**
113101
-- ASCII String --
114-
115-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
116-
bool(false)
102+
Offset not contained in string
117103
--Multibyte String --
118-
119-
Warning: mb_strripos(): Offset is greater than the length of haystack string in %s on line %d
120-
bool(false)
121-
Done
104+
Offset not contained in string

ext/mbstring/tests/mb_strrpos_empty_needle.phpt

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

7575
-- ASCII string with out of bound positive offset --
76-
77-
Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
78-
bool(false)
76+
Offset not contained in string
7977

8078
-- ASCII string with out of bound negative offset --
81-
82-
Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
83-
bool(false)
79+
Offset not contained in string
8480

8581
-- Multi-byte string without offset --
8682
int(21)
@@ -92,11 +88,7 @@ int(21)
9288
int(19)
9389

9490
-- Multi-byte string with out of bound positive offset --
95-
96-
Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
97-
bool(false)
91+
Offset not contained in string
9892

9993
-- Multi-byte string with out of bound negative offset --
100-
101-
Warning: mb_strrpos(): Offset is greater than the length of haystack string in %s on line %d
102-
bool(false)
94+
Offset not contained in string

0 commit comments

Comments
 (0)