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 <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2019-09-08 21:22:09 +02:00
parent 85843f1f29
commit 93409a784d
+6 -1
View File
@@ -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:]