Skip to content

Commit

Permalink
topdown: Fix panic in rand.intn function
Browse files Browse the repository at this point in the history
This commit just puts an error check in place to the panic from the
stdlib when rand.intn is called with an input < 1.

Signed-off-by: Torin Sandall <[email protected]>
  • Loading branch information
tsandall committed Jul 12, 2021
1 parent abb8d0c commit a1ac763
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions topdown/numbers.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func builtinRandIntn(bctx BuiltinContext, args []*ast.Term, iter func(*ast.Term)
n, err := builtins.IntOperand(args[1].Value, 2)
if err != nil {
return err
} else if n <= 0 {
return fmt.Errorf("invalid argument (n must be > 0)")
}

var key = uuidCachingKey(fmt.Sprintf("%s-%d", strOp, n))
Expand Down

0 comments on commit a1ac763

Please sign in to comment.