op: tolerate incomplete macros

Before this change, a macro not Stop'ed would result in an endless
loop during op decoding.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2022-10-04 17:11:35 -06:00
parent 24eb1a4fc5
commit 80196f3c3e
2 changed files with 23 additions and 1 deletions
+7 -1
View File
@@ -150,7 +150,13 @@ func (r *Reader) Decode() (EncodedOp, bool) {
case TypeMacro:
var op opMacroDef
op.decode(data)
r.pc = op.endpc
if op.endpc != (PC{}) {
r.pc = op.endpc
} else {
// Treat an incomplete macro as containing all remaining ops.
r.pc.data = len(r.ops.data)
r.pc.refs = len(r.ops.refs)
}
continue
}
r.pc.data += n