Skip to content

Commit

Permalink
chore: protect bits error values
Browse files Browse the repository at this point in the history
Signed-off-by: Norman <[email protected]>
  • Loading branch information
Norman authored and Norman committed Dec 25, 2024
1 parent bf7ff6f commit 8c7959a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gnovm/stdlibs/io/multi_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestMultiWriterSingleChainFlatten(t *testing.T) {
pc := make([]uintptr, 1000) // 1000 should fit the full stack
n := runtime.Callers(0, pc)
var myDepth = callDepth(pc[:n])
var writeDepth int // will contain the depth from which writerFunc.io.Writer was called
var writeDepth int // will contain the depth from which writerFunc.Writer was called
var w io.Writer = io.MultiWriter(writerFunc(func(p []byte) (int, error) {
n := runtime.Callers(1, pc)
writeDepth += callDepth(pc[:n])
Expand Down
8 changes: 4 additions & 4 deletions gnovm/stdlibs/math/bits/bits.gno
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,10 @@ func Div(hi, lo, y uint) (quo, rem uint) {
// Div32 panics for y == 0 (division by zero) or y <= hi (quotient overflow).
func Div32(hi, lo, y uint32) (quo, rem uint32) {
if y != 0 && y <= hi {
panic(OverflowError)
panic(overflowError)
}
if y == 0 {
panic(DivideError)
panic(divideError)
}
z := uint64(hi)<<32 | uint64(lo)
quo, rem = uint32(z/uint64(y)), uint32(z%uint64(y))
Expand All @@ -522,10 +522,10 @@ func Div32(hi, lo, y uint32) (quo, rem uint32) {
// Div64 panics for y == 0 (division by zero) or y <= hi (quotient overflow).
func Div64(hi, lo, y uint64) (quo, rem uint64) {
if y == 0 {
panic(DivideError)
panic(divideError)
}
if y <= hi {
panic(OverflowError)
panic(overflowError)
}

// If high part is zero, we can directly return the results.
Expand Down
4 changes: 2 additions & 2 deletions gnovm/stdlibs/math/bits/bits_errors.gno
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import (
"errors"
)

var OverflowError = errors.New("math/bits: integer overflow")
var DivideError = errors.New("math/bits: integer divide by zero")
var overflowError = errors.New("math/bits: integer overflow")
var divideError = errors.New("math/bits: integer divide by zero")
5 changes: 5 additions & 0 deletions gnovm/stdlibs/math/bits/export_test.gno
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@

package bits

// exported for tests

const DeBruijn64 = deBruijn64

var OverflowError = overflowError
var DivideError = divideError

0 comments on commit 8c7959a

Please sign in to comment.