diff --git a/encode_vm.go b/encode_vm.go index 0bc3cc5..7a08dd3 100644 --- a/encode_vm.go +++ b/encode_vm.go @@ -51,7 +51,7 @@ func errMarshaler(code *opcode, err error) *MarshalerError { func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte, error) { recursiveLevel := 0 - seenPtr := map[uintptr]struct{}{} + var seenPtr map[uintptr]struct{} ptrOffset := uintptr(0) ctxptr := ctx.ptr() @@ -211,6 +211,9 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte code = code.next break } + if seenPtr == nil { + seenPtr = map[uintptr]struct{}{} + } if _, exists := seenPtr[ptr]; exists { return nil, errUnsupportedValue(code, ptr) } @@ -288,6 +291,9 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte code = code.next break } + if seenPtr == nil { + seenPtr = map[uintptr]struct{}{} + } if _, exists := seenPtr[ptr]; exists { return nil, errUnsupportedValue(code, ptr) } @@ -992,6 +998,9 @@ func (e *Encoder) run(ctx *encodeRuntimeContext, b []byte, code *opcode) ([]byte } } } + if seenPtr == nil { + seenPtr = map[uintptr]struct{}{} + } seenPtr[ptr] = struct{}{} c := code.jmp.code c.end.next = newEndOp(&encodeCompileContext{})