File tree Expand file tree Collapse file tree 1 file changed +13
-10
lines changed
ext/mbstring/libmbfl/mbfl Expand file tree Collapse file tree 1 file changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -817,6 +817,7 @@ mbfl_strpos(
817
817
int reverse )
818
818
{
819
819
size_t result ;
820
+ size_t haystack_length ;
820
821
mbfl_string _haystack_u8 , _needle_u8 ;
821
822
const mbfl_string * haystack_u8 , * needle_u8 = NULL ;
822
823
const unsigned char * u8_tbl ;
@@ -855,29 +856,31 @@ mbfl_strpos(
855
856
needle_u8 = needle ;
856
857
}
857
858
859
+ /* Check if offset is out of bound */
860
+ haystack_length = mbfl_strlen (haystack_u8 );
861
+ if (
862
+ (offset > 0 && offset > haystack_length )
863
+ || (offset < 0 && - offset > haystack_length )
864
+ ) {
865
+ result = -16 ;
866
+ goto out ;
867
+ }
868
+
858
869
result = (size_t ) -1 ;
859
870
if (haystack_u8 -> len < needle_u8 -> len ) {
860
871
goto out ;
861
872
}
862
873
863
874
if (needle_u8 -> len == 0 ) {
864
- /* Out of bound offset */
865
- if (
866
- (offset > 0 && offset > mbfl_strlen (haystack_u8 ))
867
- || (offset < 0 && - offset > mbfl_strlen (haystack_u8 ))
868
- ) {
869
- return -16 ;
870
- }
871
-
872
875
if (reverse ) {
873
876
if (offset < 0 ) {
874
877
result = (size_t ) - offset ;
875
878
} else {
876
- result = mbfl_strlen ( haystack_u8 ) - offset ;;
879
+ result = haystack_length - offset ;;
877
880
}
878
881
} else {
879
882
if (offset < 0 ) {
880
- result = mbfl_strlen ( haystack_u8 ) + offset ;
883
+ result = haystack_length + offset ;
881
884
} else {
882
885
result = (size_t ) offset ;
883
886
}
You can’t perform that action at this time.
0 commit comments