From b2bd87df81756d4925bf1f4da6962b9dd83a807c Mon Sep 17 00:00:00 2001 From: gavynriebau Date: Sun, 5 Jun 2022 18:49:41 +0800 Subject: Fix crash due to cycles when replaying macros (#2647) In certain circumstances it was possible to get into an infinite loop when replaying macros such as when different macros attempt to replay each other. This commit adds changes to track which macros are currently being replayed and prevent getting into infinite loops.--- helix-term/src/commands.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'helix-term') diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 44e2f8c2..e7efa6c3 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -4617,6 +4617,17 @@ fn record_macro(cx: &mut Context) { fn replay_macro(cx: &mut Context) { let reg = cx.register.unwrap_or('@'); + + if cx.editor.macro_replaying.contains(®) { + cx.editor.set_error(format!( + "Cannot replay from register [{}] because already replaying from same register", + reg + )); + return; + } + + cx.editor.macro_replaying.push(reg); + let keys: Vec = if let Some([keys_str]) = cx.editor.registers.read(reg) { match helix_view::input::parse_macro(keys_str) { Ok(keys) => keys, @@ -4638,4 +4649,6 @@ fn replay_macro(cx: &mut Context) { } } })); + + cx.editor.macro_replaying.pop(); } -- cgit v1.2.3-70-g09d2