aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2024-10-30 13:54:28 +0300
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2024-10-30 14:11:16 +0300
commitff2d1376a1456d5c06e208eedd9dbc65e71e81b4 (patch)
treeaf5235bdb14db94cb442f97a2b4fba0aa6b943d3 /src
parent7c55c0c00c761144e618868325f081771f6eb74e (diff)
downloadsciteco-ff2d1376a1456d5c06e208eedd9dbc65e71e81b4.tar.gz
fixed invalid memory access when executing the F< command (but only when jumping to the beginning of the macro)
* I am not sure whether this feature is really that useful... * teco_machine_main_t::macro_pc is now pointing to the __next__ character to execute, therefore it's easier to manipulate by flow control commands. Also, it can now be unsigned (gsize) like all other program counters. * Detected thanks to running the testsuite under Valgrind.
Diffstat (limited to 'src')
-rw-r--r--src/core-commands.c2
-rw-r--r--src/parser.c6
-rw-r--r--src/parser.h4
3 files changed, 6 insertions, 6 deletions
diff --git a/src/core-commands.c b/src/core-commands.c
index 0cde7e0..27f5c64 100644
--- a/src/core-commands.c
+++ b/src/core-commands.c
@@ -1292,7 +1292,7 @@ teco_state_fcommand_loop_start(teco_machine_main_t *ctx, GError **error)
/* outside of loop */
if (!teco_expressions_discard_args(error))
return;
- ctx->macro_pc = -1;
+ ctx->macro_pc = 0;
return;
}
diff --git a/src/parser.c b/src/parser.c
index b1aa06e..5d97e9d 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -122,10 +122,10 @@ teco_machine_main_step(teco_machine_main_t *ctx, const gchar *macro, gsize stop_
ctx->macro_pc, chr, chr, ctx->parent.current, ctx->mode);
#endif
+ ctx->macro_pc = g_utf8_next_char(macro+ctx->macro_pc) - macro;
+
if (!teco_machine_input(&ctx->parent, chr, error))
goto error_attach;
-
- ctx->macro_pc = g_utf8_next_char(macro+ctx->macro_pc) - macro;
}
/*
@@ -149,7 +149,7 @@ error_attach:
* FIXME: Maybe this can be avoided altogether by passing in ctx->macro_pc
* from the callees?
*/
- teco_error_set_coord(macro, ctx->macro_pc);
+ teco_error_set_coord(macro, ctx->macro_pc-1);
return FALSE;
}
diff --git a/src/parser.h b/src/parser.h
index 066896f..659e9f9 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -447,8 +447,8 @@ typedef enum {
struct teco_machine_main_t {
teco_machine_t parent;
- /* signed because it is sometimes set to -1 for flow control */
- gssize macro_pc;
+ /** Program counter, ie. pointer to the next character in the current macro frame */
+ gsize macro_pc;
/**
* Aliases bitfield with an integer.