From 8a8edaa2daf37f7c12e21b9199755b5de8e489f5 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Fri, 7 Aug 2026 20:47:22 +0200 Subject: don't crash on `0S...$`, but always throw an error * This has been broken for some time, but it didn't crash in v2.5.2. * Even when it did not crash, the search just failed. In TECO-11 (judging by TECOC), we must throw an error, though. Video TECO on the other hand always succeeds in such cases. * Added test case --- src/search.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/search.c b/src/search.c index e1f3bc6..1b5026a 100644 --- a/src/search.c +++ b/src/search.c @@ -152,9 +152,18 @@ teco_state_search_initial(teco_machine_main_t *ctx, GError **error) teco_error_range_set(error, "S"); return FALSE; } + } else if (v2 == 0) { + /* + * NOTE: Video TECO always succeeds on `0S...$`. + * TECOC however fails just like we do. + */ + g_set_error_literal(error, TECO_ERROR, TECO_ERROR_FAILED, + "The search counter must not be zero."); + return FALSE; } else { + /* search for v2-th occurrence */ teco_search_parameters.count = (gint)v2; - if (v2 >= 0) { + if (v2 > 0) { teco_search_parameters.from = teco_search_parameters.pos; teco_search_parameters.to = teco_interface_ssm(SCI_GETLENGTH, 0, 0); } else { @@ -883,8 +892,8 @@ teco_do_search_backwards(regex_t *re, gsize from, gsize to, gint *count, GError static gboolean teco_do_search(regex_t *re, gsize from, gsize to, gint *count, GError **error) { - gboolean rc = *count >= 0 ? teco_do_search_forward(re, from, to, count, error) - : teco_do_search_backwards(re, from, to, count, error); + gboolean rc = *count > 0 ? teco_do_search_forward(re, from, to, count, error) + : teco_do_search_backwards(re, from, to, count, error); if (!rc) return FALSE; @@ -1140,6 +1149,7 @@ teco_state_search_done(teco_machine_main_t *ctx, teco_string_t str, GError **err * The optional single argument specifies the occurrence * to search (1 is the first occurrence, 2 the second, etc.). * Negative values for perform backward searches. + * must not be zero. * If missing, the sign prefix is implied for . * Therefore \(lq-S\(rq will search for the first occurrence * of before dot. -- cgit v1.2.3