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

isEmptyValue do not detect interface wrapped nil #306

Closed
wenerme opened this issue May 13, 2021 · 0 comments
Closed

isEmptyValue do not detect interface wrapped nil #306

wenerme opened this issue May 13, 2021 · 0 comments

Comments

@wenerme
Copy link
Contributor

wenerme commented May 13, 2021

Issue tracker is used for reporting bugs and discussing new features. Please use
Discord or stackoverflow for supporting
issues.

Expected Behavior

Current Behavior

/*
type Cursor struct {
	ID    models.ID `msgpack:"i"`
	Value Value     `msgpack:"v,omitempty"`
}
 */
func TestMsgPackPanic(t *testing.T) {
	var v Value
	v = (*time.Time)(nil)
	c := &Cursor{
		Value: v,
	}
	log.Println("OK Here")
	_ = msgpack.NewEncoder(bytes.NewBuffer(nil)).Encode(v)
	log.Println("Next panic")
	_ = msgpack.NewEncoder(bytes.NewBuffer(nil)).Encode(c)
}

panic here

func isEmptyValue(v reflect.Value) bool {
	if z, ok := v.Interface().(isZeroer); ok {
		return nilable(v.Kind()) && v.IsNil() || z.IsZero()
	}

Possible Solution

improve isEmptyValue

Steps to Reproduce

code above

Context (Environment)

Detailed Description

Possible Implementation

wenerme added a commit to wenerme/msgpack that referenced this issue May 24, 2021
vmihailenco added a commit that referenced this issue May 28, 2021
unwrap type to detect nil ptr prevent panic fix #306
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