From f4a7cdf543f4ec446348246bb1b2975c3f71188e Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Sat, 20 Mar 2021 18:24:13 +0900 Subject: [PATCH] Fix bugs of nil pointer of typeAddr value --- internal/encoder/compiler.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/encoder/compiler.go b/internal/encoder/compiler.go index 14344da..3bc5a80 100644 --- a/internal/encoder/compiler.go +++ b/internal/encoder/compiler.go @@ -19,11 +19,14 @@ var ( jsonNumberType = reflect.TypeOf(json.Number("")) cachedOpcodeSets []*OpcodeSet cachedOpcodeMap unsafe.Pointer // map[uintptr]*OpcodeSet - typeAddr = &runtime.TypeAddr{} + typeAddr *runtime.TypeAddr ) func init() { typeAddr = runtime.AnalyzeTypeAddr() + if typeAddr == nil { + typeAddr = &runtime.TypeAddr{} + } cachedOpcodeSets = make([]*OpcodeSet, typeAddr.AddrRange) }