From ce496a342712083526d424d965a6fa689b6b09cb Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 25 Aug 2014 19:40:46 -0700 Subject: GC correctness fixes: make sure we pin down objects for which we borrow low level C pointers, while we execute code that can cons memory. * lib.c (list_str): Protect the str argument. (int_str): Likewise. * regex.c (search_regex): protect the haystack string, while using the h pointer to its data, since regex_run can use the derivative-based engine which conses. * stream.c (vformat_str): Protect str argument, since put_char might conceivably cons. (vformat): Protect fmtstr. --- regex.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'regex.c') diff --git a/regex.c b/regex.c index 883ebb33..313a1a76 100644 --- a/regex.c +++ b/regex.c @@ -39,6 +39,7 @@ #include "parser.h" #include "signal.h" #include "unwind.h" +#include "gc.h" #include "regex.h" #include "txr.h" @@ -1800,11 +1801,17 @@ val search_regex(val haystack, val needle_regex, val start, cnum s = c_num(start); const wchar_t *h = c_str(haystack); + prot1(&haystack); + for (i = c_num(length_str(haystack)) - 1; i >= s; i--) { cnum span = regex_run(needle_regex, h + i); - if (span >= 0) + if (span >= 0) { + rel1(&haystack); return cons(num(i), num(span)); + } } + + rel1(&haystack); } else { regex_machine_t regm; val i, pos = start, retval; -- cgit v1.2.3