bytedance / sonic

A blazingly fast JSON serializing & deserializing library
Apache License 2.0
6.67k stars 332 forks source link

panic: GoString has nil pointer while its length is not zero #495

Open whatsmonster opened 1 year ago

whatsmonster commented 1 year ago

panic: val: &rt.GoString{Ptr:(unsafe.Pointer)(nil), Len:28} has nil pointer while its length is not zero!

goroutine 10928255 [running]: github.com/bytedance/sonic/encoder.goPanic(0x1, 0xc003002810) /pkg/mod/github.com/bytedance/sonic@v1.8.8/encoder/errors.go:61 +0xb7 github.com/bytedance/sonic/encoder.encodeTypedPointer(0xc0010c8498, 0x21b9760, 0xc000635950, 0xc0095d4000, 0x0, 0x0, 0xc93) /pkg/mod/github.com/bytedance/sonic@v1.8.8/encoder/primitives.go:77 +0x16c github.com/bytedance/sonic/encoder.encodeTypedPointer(0xc0010c8498, 0x2156020, 0xc004a685c8, 0xc0095d4000, 0x0, 0xc0010c8498, 0x18) /pkg/mod/github.com/bytedance/sonic@v1.8.8/encoder/primitives.go:83 +0x1f5 github.com/bytedance/sonic/encoder.encodeInto(0xc0010c8498, 0x2156020, 0xc001124480, 0x0, 0x1, 0x18) /pkg/mod/github.com/bytedance/sonic@v1.8.8/encoder/encoder.go:211 +0xdf github.com/bytedance/sonic/encoder.EncodeInto(0xc0010c8498, 0x2156020, 0xc001124480, 0x0, 0x7fd081b405b8, 0x40) /pkg/mod/github.com/bytedance/sonic@v1.8.8/encoder/encoder.go:200 +0x4d github.com/bytedance/sonic/encoder.(StreamEncoder).Encode(0xc008a55a20, 0x2156020, 0xc001124480, 0x2715eb4, 0x1d) /pkg/mod/github.com/bytedance/sonic@v1.8.8/encoder/stream.go:42 +0xdd log.(jsonFormatter).Format(0x414d638, 0xc006a4a190, 0xc005acab08, 0x2, 0x2, 0xc006938120, 0x21)

type Data struct {
    Msg   string    `json:"msg"`
        ....
}

if err := encoder.NewStreamEncoder(buf).Encode(&struct {
        *Data
        Extra      int    `json:"extra"`
    }{
        Data:   data,
        Extra:  extra,
    }); err != nil {
        return nil, err
    }

return buf.Bytes(), nil
liuq19 commented 1 year ago

maybe have a concurrency problem, you could use -race to check it