diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2014-08-25 19:40:46 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2014-08-25 19:40:46 -0700 |
commit | ce496a342712083526d424d965a6fa689b6b09cb (patch) | |
tree | 536e18bef4680100bd7fb9182939efaf490c3e88 /regex.c | |
parent | b8109c296982b8641a47f9cb6223b6102fef4b8c (diff) | |
download | txr-ce496a342712083526d424d965a6fa689b6b09cb.tar.gz txr-ce496a342712083526d424d965a6fa689b6b09cb.tar.bz2 txr-ce496a342712083526d424d965a6fa689b6b09cb.zip |
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.
Diffstat (limited to 'regex.c')
-rw-r--r-- | regex.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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; |