Fix checkptr error for array decoder

This commit is contained in:
Masaaki Goshima 2022-12-02 01:51:29 +09:00
parent 50a60f932b
commit 1480e0046f
No known key found for this signature in database
GPG Key ID: 6A53785055537153
2 changed files with 13 additions and 1 deletions

View File

@ -4005,3 +4005,13 @@ func TestIssue384(t *testing.T) {
}
}
}
func TestIssue408(t *testing.T) {
type T struct {
Arr [2]int32 `json:"arr"`
}
var v T
if err := json.Unmarshal([]byte(`{"arr": [1,2]}`), &v); err != nil {
t.Fatal(err)
}
}

View File

@ -19,7 +19,9 @@ type arrayDecoder struct {
}
func newArrayDecoder(dec Decoder, elemType *runtime.Type, alen int, structName, fieldName string) *arrayDecoder {
zeroValue := *(*unsafe.Pointer)(unsafe_New(elemType))
// workaround to avoid checkptr errors. cannot use `*(*unsafe.Pointer)(unsafe_New(elemType))` directly.
zeroValuePtr := unsafe_New(elemType)
zeroValue := **(**unsafe.Pointer)(unsafe.Pointer(&zeroValuePtr))
return &arrayDecoder{
valueDecoder: dec,
elemType: elemType,