Skip to content

Commit

Permalink
btf: improve use of reflection API in FindType
Browse files Browse the repository at this point in the history
Signed-off-by: Fabio Falzoi <fabio.falzoi84@gmail.com>
  • Loading branch information
Fabio Falzoi authored and lmb committed Sep 17, 2021
1 parent 1ec250c commit fc2955d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions internal/btf/btf.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ func (s *Spec) FindType(name string, typ interface{}) error {
return fmt.Errorf("%T is not a pointer", typ)
}

typPtr := reflect.Indirect(typValue)
typPtr := typValue.Elem()
if !typPtr.CanSet() {
return fmt.Errorf("%T cannot be set", typ)
}
Expand Down Expand Up @@ -510,7 +510,7 @@ func (s *Spec) FindType(name string, typ interface{}) error {
return fmt.Errorf("type %s: %w", name, ErrNotFound)
}

typPtr.Set(reflect.Indirect(reflect.ValueOf(candidate)).Addr())
typPtr.Set(reflect.ValueOf(candidate))

return nil
}
Expand Down

0 comments on commit fc2955d

Please sign in to comment.