cli/vm: use ParseInt to properly (and easily) check for int32

This commit is contained in:
Roman Khimov 2022-10-07 17:10:04 +03:00
parent 735db08f84
commit 4d2afa2624

View file

@ -10,7 +10,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"math"
"math/big" "math/big"
"os" "os"
"strconv" "strconv"
@ -1026,13 +1025,10 @@ func getDumpArgs(c *cli.Context) (int32, []byte, error) {
) )
h, err := flags.ParseAddress(hashOrID) h, err := flags.ParseAddress(hashOrID)
if err != nil { if err != nil {
i, err := strconv.Atoi(hashOrID) i, err := strconv.ParseInt(hashOrID, 10, 32)
if err != nil { if err != nil {
return 0, nil, fmt.Errorf("failed to parse contract hash, address or ID: %w", err) return 0, nil, fmt.Errorf("failed to parse contract hash, address or ID: %w", err)
} }
if i > math.MaxInt32 {
return 0, nil, fmt.Errorf("contract ID exceeds max int32 value")
}
id = int32(i) id = int32(i)
} else { } else {
cs, err := ic.GetContract(h) cs, err := ic.GetContract(h)