forked from mirror/go-json
Fix pointer alignment error
This commit is contained in:
parent
e38c3606b3
commit
e660ae468d
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
type sliceDecoder struct {
|
||||
elemType *rtype
|
||||
isElemPointerType bool
|
||||
valueDecoder decoder
|
||||
size uintptr
|
||||
arrayPool sync.Pool
|
||||
|
@ -32,6 +33,7 @@ func newSliceDecoder(dec decoder, elemType *rtype, size uintptr, structName, fie
|
|||
return &sliceDecoder{
|
||||
valueDecoder: dec,
|
||||
elemType: elemType,
|
||||
isElemPointerType: elemType.Kind() == reflect.Ptr,
|
||||
size: size,
|
||||
arrayPool: sync.Pool{
|
||||
New: func() interface{} {
|
||||
|
@ -115,7 +117,9 @@ func (d *sliceDecoder) decodeStream(s *stream, depth int64, p unsafe.Pointer) er
|
|||
copySlice(d.elemType, dst, src)
|
||||
}
|
||||
ep := unsafe.Pointer(uintptr(data) + uintptr(idx)*d.size)
|
||||
if d.isElemPointerType {
|
||||
*(*unsafe.Pointer)(ep) = nil // initialize elem pointer
|
||||
}
|
||||
if err := d.valueDecoder.decodeStream(s, depth, ep); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -227,7 +231,9 @@ func (d *sliceDecoder) decode(buf []byte, cursor, depth int64, p unsafe.Pointer)
|
|||
copySlice(d.elemType, dst, src)
|
||||
}
|
||||
ep := unsafe.Pointer(uintptr(data) + uintptr(idx)*d.size)
|
||||
if d.isElemPointerType {
|
||||
*(*unsafe.Pointer)(ep) = nil // initialize elem pointer
|
||||
}
|
||||
c, err := d.valueDecoder.decode(buf, cursor, depth, ep)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
|
Loading…
Reference in New Issue