From 93409a784d7c687a9883e2d9bb18c57ce563b3fc Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sun, 8 Sep 2019 21:22:09 +0200 Subject: [PATCH] ui: fill out the MacroOp opcode in Record to support unfinished macros Before this change MacroOp.Record simply reserved enough space for Stop to fill out. If a user Record but never Stop'ed a MacroOp, the resulting Ops buffer would end up with a zero, invalid opcode and panic at decode. Fill out an empty MacroOp at Record, ensuring the Ops remains valid. Signed-off-by: Elias Naur --- ui/ops.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ui/ops.go b/ui/ops.go index f4a22891..09dec7b8 100644 --- a/ui/ops.go +++ b/ui/ops.go @@ -157,8 +157,9 @@ func (m *MacroOp) Record(o *Ops) { m.recording = true m.ops = o m.pc = o.pc() - // Make room for a macro definition. Filled out in Stop. + // Reserve room for a macro definition. Updated in Stop. m.ops.Write(make([]byte, opconst.TypeMacroDefLen)) + m.fill() } // Stop ends a previously started recording. @@ -167,6 +168,10 @@ func (m *MacroOp) Stop() { panic("not recording") } m.recording = false + m.fill() +} + +func (m *MacroOp) fill() { pc := m.ops.pc() // Fill out the macro definition reserved in Record. data := m.ops.data[m.pc.data:]