Skip to content

Commit

Permalink
Fix overflow on 32-bit archs (#98)
Browse files Browse the repository at this point in the history
* Fix overflow on 32-bit archs

packFormatReader uses an uint for its option size, so maxDecuplable must
not overflow uint.

* Properly format integer value as string

On architectures where int is narrower than int64, integer values
would be formatted incorrectly when converted to string with
strconv.Itoa. Using strconv.FormatInt fixes this.
  • Loading branch information
TheCount authored Feb 4, 2023
1 parent 0907c3f commit 35f260b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/stringlib/packformatreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (p *packFormatReader) smallOptSize(defaultSize uint) (ok bool) {
return
}

const maxDecuplable = math.MaxUint64 / 10
const maxDecuplable = math.MaxUint / 10

func (p *packFormatReader) getOptSize() bool {
var (
Expand Down
2 changes: 1 addition & 1 deletion runtime/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (v Value) ToString() (string, bool) {
}
switch x := v.iface.(type) {
case int64:
return strconv.Itoa(int(v.AsInt())), true
return strconv.FormatInt(v.AsInt(), 10), true
case float64:
return strconv.FormatFloat(v.AsFloat(), 'g', -1, 64), true
case bool:
Expand Down

0 comments on commit 35f260b

Please sign in to comment.