mirror of https://github.com/goccy/go-json.git
Merge pull request #415 from goccy/fix-array-checkptr-error
Fix checkptr error for array decoder
This commit is contained in:
commit
a2149a5b25
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -19,7 +19,9 @@ type arrayDecoder struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newArrayDecoder(dec Decoder, elemType *runtime.Type, alen int, structName, fieldName string) *arrayDecoder {
|
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{
|
return &arrayDecoder{
|
||||||
valueDecoder: dec,
|
valueDecoder: dec,
|
||||||
elemType: elemType,
|
elemType: elemType,
|
||||||
|
|
Loading…
Reference in New Issue