diff options
| -rw-r--r-- | src/search.c | 30 | ||||
| -rw-r--r-- | tests/testsuite.at | 3 |
2 files changed, 23 insertions, 10 deletions
diff --git a/src/search.c b/src/search.c index 1b5026a..357a0c0 100644 --- a/src/search.c +++ b/src/search.c @@ -152,14 +152,6 @@ 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; @@ -172,6 +164,16 @@ teco_state_search_initial(teco_machine_main_t *ctx, GError **error) } } + if (!teco_search_parameters.count) { + /* + * 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; + } + teco_search_parameters.from_buffer = teco_qreg_current ? NULL : teco_ring_current; teco_search_parameters.to_buffer = NULL; return TRUE; @@ -1251,7 +1253,17 @@ teco_state_search_all_initial(teco_machine_main_t *ctx, GError **error) } } - if (teco_search_parameters.count >= 0) { + if (!teco_search_parameters.count) { + /* + * NOTE: Video TECO always succeeds on `0N...$`. + * 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; + } + + if (teco_search_parameters.count > 0) { teco_search_parameters.from = teco_search_parameters.pos; teco_search_parameters.to = teco_interface_ssm(SCI_GETLENGTH, 0, 0); } else { diff --git a/tests/testsuite.at b/tests/testsuite.at index 49b0673..5d4ec43 100644 --- a/tests/testsuite.at +++ b/tests/testsuite.at @@ -293,8 +293,9 @@ 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 +# 0-th searches: must always fail, but not crash TE_CHECK([[@I/XYZ/ J 0@S/XYZ/]], 1, ignore, ignore) +TE_CHECK([[@I/XYZ/ J 0@N/XYZ/]], 1, ignore, ignore) AT_CLEANUP AT_SETUP([Searches over buffer boundaries]) |
