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

Fix possible panics in slice type assertion #1049

Merged
merged 1 commit into from
Jan 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions flag_float64_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,9 @@ func (c *Context) Float64Slice(name string) []float64 {
func lookupFloat64Slice(name string, set *flag.FlagSet) []float64 {
f := set.Lookup(name)
if f != nil {
parsed, err := (f.Value.(*Float64Slice)).Value(), error(nil)
if err != nil {
return nil
if slice, ok := f.Value.(*Float64Slice); ok {
return slice.Value()
}
return parsed
}
return nil
}
6 changes: 2 additions & 4 deletions flag_int64_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,9 @@ func (c *Context) Int64Slice(name string) []int64 {
func lookupInt64Slice(name string, set *flag.FlagSet) []int64 {
f := set.Lookup(name)
if f != nil {
parsed, err := (f.Value.(*Int64Slice)).Value(), error(nil)
if err != nil {
return nil
if slice, ok := f.Value.(*Int64Slice); ok {
return slice.Value()
}
return parsed
}
return nil
}
6 changes: 2 additions & 4 deletions flag_int_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,9 @@ func (c *Context) IntSlice(name string) []int {
func lookupIntSlice(name string, set *flag.FlagSet) []int {
f := set.Lookup(name)
if f != nil {
parsed, err := (f.Value.(*IntSlice)).Value(), error(nil)
if err != nil {
return nil
if slice, ok := f.Value.(*IntSlice); ok {
return slice.Value()
}
return parsed
}
return nil
}
6 changes: 2 additions & 4 deletions flag_string_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,9 @@ func (c *Context) StringSlice(name string) []string {
func lookupStringSlice(name string, set *flag.FlagSet) []string {
f := set.Lookup(name)
if f != nil {
parsed, err := (f.Value.(*StringSlice)).Value(), error(nil)
if err != nil {
return nil
if slice, ok := f.Value.(*StringSlice); ok {
return slice.Value()
}
return parsed
}
return nil
}