Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic: reflect: reflect.Value.SetString using unaddressable value #339

Open
TXYH1 opened this issue Jul 28, 2022 · 0 comments
Open

panic: reflect: reflect.Value.SetString using unaddressable value #339

TXYH1 opened this issue Jul 28, 2022 · 0 comments

Comments

@TXYH1
Copy link

TXYH1 commented Jul 28, 2022

This code will panic, And I found it is because of github.com/vmihailenco/msgpack/v5/decode_ value.go:130, Therefore, if I replace S1 with a null pointer, there will be no panic. Is this a bug

image

func TestMsgpack(t *testing.T) {
	type demo struct{}
	t1 := []interface{}{nil}
	data, _ := Marshal(t1)
	//var s1 *demo
	s1 := new(demo)
	us := []interface{}{s1}
	Unmarshal(data, &us)

}

func Marshal(v interface{}) ([]byte, error) {
	enc := msgpack.GetEncoder()
	defer msgpack.PutEncoder(enc)

	var buf bytes.Buffer
	enc.Reset(&buf)

	err := enc.Encode(v)
	if err != nil {
		return nil, err
	}
	return buf.Bytes(), err
}

func Unmarshal(data []byte, v interface{}) error {
	dec := msgpack.GetDecoder()
	defer msgpack.PutDecoder(dec)

	dec.Reset(bytes.NewReader(data))
	err := dec.Decode(v)

	return err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant