mirror of https://github.com/goccy/go-json.git
Merge pull request #276 from goccy/feature/fix-nil-slice
Fix assign nil slice value
This commit is contained in:
commit
d7cdabe600
|
@ -9,6 +9,13 @@ import (
|
||||||
"github.com/goccy/go-json/internal/runtime"
|
"github.com/goccy/go-json/internal/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
sliceType = runtime.Type2RType(
|
||||||
|
reflect.TypeOf((*sliceHeader)(nil)).Elem(),
|
||||||
|
)
|
||||||
|
nilSlice = unsafe.Pointer(&sliceHeader{})
|
||||||
|
)
|
||||||
|
|
||||||
type sliceDecoder struct {
|
type sliceDecoder struct {
|
||||||
elemType *runtime.Type
|
elemType *runtime.Type
|
||||||
isElemPointerType bool
|
isElemPointerType bool
|
||||||
|
@ -107,7 +114,7 @@ func (d *sliceDecoder) DecodeStream(s *Stream, depth int64, p unsafe.Pointer) er
|
||||||
if err := nullBytes(s); err != nil {
|
if err := nullBytes(s); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
*(*unsafe.Pointer)(p) = nil
|
typedmemmove(sliceType, p, nilSlice)
|
||||||
return nil
|
return nil
|
||||||
case '[':
|
case '[':
|
||||||
s.cursor++
|
s.cursor++
|
||||||
|
@ -216,7 +223,7 @@ func (d *sliceDecoder) Decode(ctx *RuntimeContext, cursor, depth int64, p unsafe
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
cursor += 4
|
cursor += 4
|
||||||
*(*unsafe.Pointer)(p) = nil
|
typedmemmove(sliceType, p, nilSlice)
|
||||||
return cursor, nil
|
return cursor, nil
|
||||||
case '[':
|
case '[':
|
||||||
cursor++
|
cursor++
|
||||||
|
|
Loading…
Reference in New Issue