From b016f781647ce0aec03f98cb67d743983b5d6038 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Thu, 7 Nov 2024 22:13:50 +0300 Subject: if a macro ends without finding a goto label, always throw a 'Label "..." not found' error * This is important with gotos in loops as in <@O/x/> where, we would otherwise get a confusing "Unterminated loop" error. * This in particular fixes the error thrown in grosciteco.tes when encountering a new unknown command. --- src/parser.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/parser.c') diff --git a/src/parser.c b/src/parser.c index d08b8aa..4ee6a90 100644 --- a/src/parser.c +++ b/src/parser.c @@ -216,6 +216,13 @@ teco_execute_macro(const gchar *macro, gsize macro_len, teco_loop_stack->len - macro_machine.loop_stack_fp); } + if (G_UNLIKELY(teco_goto_skip_label.len > 0)) { + g_autofree gchar *label_printable = teco_string_echo(teco_goto_skip_label.data, teco_goto_skip_label.len); + g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, + "Label \"%s\" not found", label_printable); + goto error_attach; + } + if (G_UNLIKELY(teco_loop_stack->len > macro_machine.loop_stack_fp)) { const teco_loop_context_t *ctx = &g_array_index(teco_loop_stack, teco_loop_context_t, teco_loop_stack->len-1); /* ctx->pc points to the character after the loop start command */ @@ -226,13 +233,6 @@ teco_execute_macro(const gchar *macro, gsize macro_len, goto error_cleanup; } - if (G_UNLIKELY(teco_goto_skip_label.len > 0)) { - g_autofree gchar *label_printable = teco_string_echo(teco_goto_skip_label.data, teco_goto_skip_label.len); - g_set_error(error, TECO_ERROR, TECO_ERROR_FAILED, - "Label \"%s\" not found", label_printable); - goto error_attach; - } - /* * Some states (esp. commands involving a * "lookahead") are valid at the end of a macro. -- cgit v1.2.3