From d556aee67e615b48c25861741d28d103109235e3 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 15 Oct 2024 23:33:43 +0300 Subject: fixed memory corruptions due to undoing the teco_machine_stringbuilding_t::codepage * It's contained in teco_machine_main_t which is created per macro call frame. So after macro calls, the machine no longer exists. It is therefore unsafe to undo its members indiscriminately. * On the other hand, we must undo the codepage setting when run interactively, so it is now only undone when belonging to the commandline macro frame. * This was actually causing memory corruptions on every fnkeys cursor movement, but never caused crashes - probably because the invalid pointers are always pointing to unused parts of the C call stack. * Initially broken in b31b8871. --- src/spawn.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/spawn.c') diff --git a/src/spawn.c b/src/spawn.c index 445acc5..cb1ef75 100644 --- a/src/spawn.c +++ b/src/spawn.c @@ -43,6 +43,7 @@ #include "core-commands.h" #include "qreg-commands.h" #include "error.h" +#include "cmdline.h" #include "spawn.h" /* @@ -167,8 +168,12 @@ teco_state_execute_initial(teco_machine_main_t *ctx, GError **error) /* * Command-lines and file names are always assumed to be UTF-8, * unless we set TECO_ED_DEFAULT_ANSI. + * + * NOTE: This is not safe to undo in macro calls. */ - teco_undo_guint(ctx->expectstring.machine.codepage) = teco_default_codepage(); + if (ctx == &teco_cmdline.machine) + teco_undo_guint(ctx->expectstring.machine.codepage); + ctx->expectstring.machine.codepage = teco_default_codepage(); if (!teco_expressions_eval(FALSE, error)) return FALSE; -- cgit v1.2.3