Merge pull request #415 from goccy/fix-array-checkptr-error

Fix checkptr error for array decoder
This commit is contained in:
Masaaki Goshima 2022-12-02 01:58:57 +09:00 committed by GitHub
commit a2149a5b25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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,