Skip to content

Commit

Permalink
Merge pull request #415 from goccy/fix-array-checkptr-error
Browse files Browse the repository at this point in the history
Fix checkptr error for array decoder
  • Loading branch information
goccy committed Dec 1, 2022
2 parents 50a60f9 + 1480e00 commit a2149a5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
4 changes: 3 additions & 1 deletion internal/decoder/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a2149a5

Please sign in to comment.