Fix initialize seenPtr

This commit is contained in:
Masaaki Goshima 2020-12-20 19:08:20 +09:00
parent d85327b458
commit 7083274627
1 changed files with 10 additions and 1 deletions

View File

@ -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{})