summaryrefslogtreecommitdiffstats
path: root/regex.c
diff options
context:
space:
mode:
Diffstat (limited to 'regex.c')
-rw-r--r--regex.c9
1 files changed, 8 insertions, 1 deletions
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;