Skip to content

Commit

Permalink
Avoid overflowing int and uint on 32-bit systems (#184)
Browse files Browse the repository at this point in the history
This fixes a bug where, on 32-bit operating systems, a large integer
value would overflow when boxed from a 64-bit int/uint (from
ParseInt/ParseUint) to a 32bit int/uint.
  • Loading branch information
sethvargo authored Aug 16, 2023
1 parent fb4ffd9 commit 201bd0c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ type IntVar struct {

func (f *FlagSection) IntVar(i *IntVar) {
parser := func(s string) (int, error) {
v, err := strconv.ParseInt(s, 10, 64)
v, err := strconv.ParseInt(s, 10, strconv.IntSize)
return int(v), err
}
printer := func(v int) string { return strconv.FormatInt(int64(v), 10) }
Expand Down Expand Up @@ -817,7 +817,7 @@ type UintVar struct {

func (f *FlagSection) UintVar(i *UintVar) {
parser := func(s string) (uint, error) {
v, err := strconv.ParseUint(s, 10, 64)
v, err := strconv.ParseUint(s, 10, strconv.IntSize)
return uint(v), err
}
printer := func(v uint) string { return strconv.FormatUint(uint64(v), 10) }
Expand Down

0 comments on commit 201bd0c

Please sign in to comment.