diff options
| -rw-r--r-- | TODO | 6 | ||||
| m--------- | contrib/terex | 0 | ||||
| -rw-r--r-- | src/search.c | 23 |
3 files changed, 7 insertions, 22 deletions
@@ -74,12 +74,6 @@ Known Bugs: and b) the file mode and ownership of re-created files can be preserved. We should fall back silently to an (inefficient) memory copy or temporary file strategy if this is detected. - * It is still possible to hang searches on huge files since a single match - could still scan too much memory - e.g. try searching for a word that - occurs only at the end of the huge file. - Can probably be avoided by including `(*MATCH_LIMIT=d)` in the pattern. - A new regexp engine should also allow interruptions within a single match, - so we don't have to invent limits like that. * It is still possible to crash SciTECO using recursive functions, since they map to the C program's call stack. It is perhaps best to use another stack of diff --git a/contrib/terex b/contrib/terex -Subproject fa3d463a4cd563f3c5f29331f48a0161bf58686 +Subproject d71d7527a8be8654560867d761036598408bfe1 diff --git a/src/search.c b/src/search.c index 491ddbb..1ab925c 100644 --- a/src/search.c +++ b/src/search.c @@ -708,14 +708,6 @@ teco_do_search_forward(regex_t *re, gsize from, gsize to, gint *count, GError ** 1+re->re_nsub, info, eflags)) == REG_OKAY && --(*count)) { buffer += info[0].rm_eo; from += info[0].rm_eo; - - /* - * FIXME: A single pathological match could already be excessively slow. - */ - if (G_UNLIKELY(teco_interface_is_interrupted())) { - teco_error_interrupted_set(error); - return FALSE; - } } if (rc == REG_OKAY) { @@ -810,14 +802,6 @@ teco_do_search_backwards(regex_t *re, gsize from, gsize to, gint *count, GError gint rc; for (;;) { - /* - * FIXME: A single pathological match could already be excessively slow. - */ - if (G_UNLIKELY(teco_interface_is_interrupted())) { - teco_error_interrupted_set(error); - return FALSE; - } - rc = tere_exec(re, (const chr *)buffer+from_block+offset, to_block-from_block-offset, &details, 1+re->re_nsub, info, eflags); if (rc != REG_OKAY) @@ -1000,6 +984,13 @@ teco_state_search_process(teco_machine_main_t *ctx, teco_string_t str, gsize new if (rc != REG_OKAY) goto failure; + /* + * Check for interruptions during matching since they can be quite slow + * especially when matching with regular expressions and backreferences + * (e.g. @S/^~(.*)\1/). + */ + tere_set_is_interrupted_cb(&re, teco_interface_is_interrupted); + if (!teco_qreg_current && teco_ring_current != teco_search_parameters.from_buffer) { teco_ring_undo_edit(); |
