From 7083274627bac3f9fbbedf8380ffe19dea094634 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Sun, 20 Dec 2020 19:08:20 +0900 Subject: [PATCH] Fix initialize seenPtr --- encode_vm.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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{})