aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <rhaberkorn@fmsbw.de>2026-08-07 20:47:22 +0200
committerRobin Haberkorn <rhaberkorn@fmsbw.de>2026-08-07 21:23:59 +0200
commit8a8edaa2daf37f7c12e21b9199755b5de8e489f5 (patch)
treed6b9607bc1a0c3f47ac5573dc71472499225fad9
parent7a6e1ebb6e3257d62a472fe41aaead910904da54 (diff)
don't crash on `0S...$`, but always throw an errorHEADmaster-fmsbw-cimaster
* 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
-rw-r--r--src/search.c16
-rw-r--r--tests/testsuite.at2
2 files changed, 15 insertions, 3 deletions
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 <n> perform backward searches.
+ * <n> must not be zero.
* If missing, the sign prefix is implied for <n>.
* Therefore \(lq-S\(rq will search for the first occurrence
* of <pattern> before dot.
diff --git a/tests/testsuite.at b/tests/testsuite.at
index 571b5b7..eadf4fe 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -293,6 +293,8 @@ TE_CHECK([[@I/АБВГД/J -^X :@S/в/"S(0/0)']], 0, ignore, ignore)
TE_CHECK([[-^X @^Um{^X} Mm-0"N(0/0)']], 0, ignore, ignore)
# Anchored search
TE_CHECK([[@I/XYZ/ J ::@S/X/"F(0/0)' H::@S/Z/"S(0/0)']], 0, ignore, ignore)
+# 0-th searches: must always fail
+TE_CHECK([[@I/XYZ/ J 0@S/XYZ/]], 1, ignore, ignore)
AT_CLEANUP
AT_SETUP([Searches over buffer boundaries])