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"
"fmt"
"io"
"math"
"math/big"
"os"
"strconv"
@ -1026,13 +1025,10 @@ func getDumpArgs(c *cli.Context) (int32, []byte, error) {
)
h, err := flags.ParseAddress(hashOrID)
if err != nil {
i, err := strconv.Atoi(hashOrID)
i, err := strconv.ParseInt(hashOrID, 10, 32)
if err != nil {
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)
} else {
cs, err := ic.GetContract(h)