Skip to content

Commit bb16682

Browse files
committed
FIX: Negative /SKIP with FIND causing a hang
fixes: Oldes/Rebol-issues#2291
1 parent a7edfd3 commit bb16682

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/core/t-string.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,10 @@ static REBSER *make_binary(REBVAL *arg, REBOOL make)
528528

529529
if (args & AM_FIND_PART) tail = index + Partial(value, 0, D_ARG(ARG_FIND_LENGTH), 0);
530530
ret = 1; // skip size
531-
if (args & AM_FIND_SKIP) ret = Partial(value, 0, D_ARG(ARG_FIND_SIZE), 0);
531+
if (args & AM_FIND_SKIP) {
532+
ret = Partial(value, 0, D_ARG(ARG_FIND_SIZE), 0);
533+
if(!ret) goto is_none;
534+
}
532535

533536
if (action == A_SELECT) args |= AM_FIND_TAIL;
534537

src/tests/units/series-test.r3

+8
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ Rebol [
7878
--assert "b" = find/case str #"b"
7979
--assert none? find/case str #"B"
8080

81+
--test-- "FIND with negative skip"
82+
;@@ https://github.com/Oldes/Rebol-issues/issues/2291
83+
--assert none? find/skip "acdcde" "cd" -3
84+
--assert "cde" = find/skip/reverse tail "acd000cde" "cd" -3
85+
--assert "cde111" = find/skip/reverse tail "acd000cde111" "cd" -3
86+
; I'm not sure with the next one, but I will keep it:
87+
--assert "cde" = find/reverse/skip tail "acde" make bitset! #"c" -2
88+
8189
--test-- https://github.com/Oldes/Rebol-issues/issues/66
8290
--assert none? find/skip [1 2 3 4 5 6] 2 3
8391

0 commit comments

Comments
 (0)