Skip to content

Commit

Permalink
Fix possible access to fromspace in knuth_morris_pratt_string_index
Browse files Browse the repository at this point in the history
collapse_strands may allocate, so we need to keep Haystack updated
  • Loading branch information
niner committed Jul 27, 2019
1 parent e0bc6e2 commit 6730e51
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/strings/ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -1294,9 +1294,14 @@ static MVMint64 knuth_morris_pratt_string_index (MVMThreadContext *tc, MVMString
next_is_malloced = 1;
}
/* If the needle is a strand, flatten it, otherwise use the original string */
flat_needle = needle->body.storage_type == MVM_STRING_STRAND
? collapse_strands(tc, needle)
: needle;
if (needle->body.storage_type == MVM_STRING_STRAND) {
MVMROOT(tc, Haystack, {
flat_needle = collapse_strands(tc, needle);
});
}
else {
flat_needle = needle;
}
/* Process the needle into a jump table put into variable 'next' */
knuth_morris_pratt_process_pattern(tc, flat_needle, next, needle_graphs);
/* If the Haystack is a strand, use MVM_string_gi_cached_get_grapheme
Expand Down

0 comments on commit 6730e51

Please sign in to comment.