Skip to content

Commit 9526ae7

Browse files
committed
Don't check for null pointer as in MRI.
1 parent c765b8a commit 9526ae7

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

core/src/main/java/org/jruby/util/StringSupport.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -893,9 +893,7 @@ public static int countCommon19(ByteList value, Ruby runtime, boolean[] table, T
893893
return i;
894894
}
895895

896-
/**
897-
* rb_str_rindex_m
898-
*/
896+
// MRI: rb_str_rindex
899897
public static int rindex(ByteList source, int sourceChars, int subChars, int pos, CodeRangeable subStringCodeRangeable, Encoding enc) {
900898
if (subStringCodeRangeable.scanForCodeRange() == CR_BROKEN) return -1;
901899

@@ -927,7 +925,8 @@ public static int rindex(ByteList source, int sourceChars, int subChars, int pos
927925
if (subSize == 0) return pos;
928926
int t = subString.begin();
929927

930-
while (s > 0 && s + subSize <= sourceSize) {
928+
// s >= 0 because -1 is our OOB, where MRI's is null pointer (0)
929+
while (s >= 0 && s + subSize <= sourceSize) {
931930
if (ByteList.memcmp(sourceBytes, s, subBytes, t, subSize) == 0) {
932931
return pos;
933932
}

0 commit comments

Comments
 (0)