Skip to content

Commit

Permalink
Clean up setuint
Browse files Browse the repository at this point in the history
Signed-off-by: Kimmo Lehto <[email protected]>
  • Loading branch information
kke committed Apr 3, 2024
1 parent a92b8e7 commit 82a46f8
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions sshconfig/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ func (s *Setter) setUint(key string, values ...string) error { //nolint:cyclop
if err := expectOne(values); err != nil {
return err
}
var uval uint
var uval uint64
if strings.HasPrefix(values[0], "0") && len(values[0]) > 1 { //nolint:nestif
v, err := strconv.ParseUint(values[0], 8, 64)
if err != nil {
Expand All @@ -348,7 +348,7 @@ func (s *Setter) setUint(key string, values ...string) error { //nolint:cyclop
if v > uint64(math.MaxUint) {
return fmt.Errorf("%w: invalid uint value %q", errInvalidValue, values[0])
}
uval = uint(v)
uval = v
} else {
v, err := strconv.ParseUint(values[0], 10, 64)
if err != nil {
Expand All @@ -357,7 +357,7 @@ func (s *Setter) setUint(key string, values ...string) error { //nolint:cyclop
if v > uint64(math.MaxUint) {
return fmt.Errorf("%w: invalid uint value %q", errInvalidValue, values[0])
}
uval = uint(v)
uval = v
}
field, err := s.get(key, reflect.Uint)
if err != nil {
Expand All @@ -368,20 +368,14 @@ func (s *Setter) setUint(key string, values ...string) error { //nolint:cyclop
return nil
}
uintPtr := reflect.New(reflect.TypeOf(uval))
uintPtr.Elem().SetInt(int64(uval))
uintPtr.Elem().SetUint(uval)
field.Set(uintPtr)
} else {
if field.Uint() != 0 {
return nil
}
field.SetUint(uint64(uval))
return nil
}
if !field.IsZero() {
if field.Uint() != 0 {
return nil
}
uintPtr := reflect.New(reflect.TypeOf(uval))
uintPtr.Elem().SetUint(uint64(uval))
field.Set(uintPtr)
field.SetUint(uval)
return nil
}

Expand Down

0 comments on commit 82a46f8

Please sign in to comment.