mirror of https://github.com/goccy/go-json.git
Fix checkptr error for array decoder
This commit is contained in:
parent
50a60f932b
commit
1480e0046f
|
@ -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 {
|
||||
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,
|
||||
|
|
Loading…
Reference in New Issue