mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
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:
@@ -150,7 +150,13 @@ func (r *Reader) Decode() (EncodedOp, bool) {
|
|||||||
case TypeMacro:
|
case TypeMacro:
|
||||||
var op opMacroDef
|
var op opMacroDef
|
||||||
op.decode(data)
|
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
|
continue
|
||||||
}
|
}
|
||||||
r.pc.data += n
|
r.pc.data += n
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ package op
|
|||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"gioui.org/internal/ops"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTransformChecks(t *testing.T) {
|
func TestTransformChecks(t *testing.T) {
|
||||||
@@ -18,3 +20,17 @@ func TestTransformChecks(t *testing.T) {
|
|||||||
Record(&ops)
|
Record(&ops)
|
||||||
trans.Pop()
|
trans.Pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIncompleteMacroReader(t *testing.T) {
|
||||||
|
var o Ops
|
||||||
|
// Record, but don't Stop it.
|
||||||
|
Record(&o)
|
||||||
|
Offset(image.Point{}).Push(&o)
|
||||||
|
|
||||||
|
var r ops.Reader
|
||||||
|
|
||||||
|
r.Reset(&o.Internal)
|
||||||
|
if _, more := r.Decode(); more {
|
||||||
|
t.Error("decoded an operation from a semantically empty Ops")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user