Update token_contract.go, checking the input params > 0 in function sub().

Signed-off-by: yjwxfq <112159687+yjwxfq@users.noreply.github.com>
This commit is contained in:
yjwxfq 2023-06-20 16:00:24 +08:00 committed by Dave Enyeart
parent 9a4920d565
commit 7671bdd7c6

View file

@ -719,13 +719,15 @@ func checkInitialized(ctx contractapi.TransactionContextInterface) (bool, error)
// sub two number checking for overflow
func sub(b int, q int) (int, error) {
// Check overflow
// sub two number checking
if q <= 0 {
return 0, fmt.Errorf("Error: the subtraction number is %d, it should be greater than 0", q)
}
if b < q {
return 0, fmt.Errorf("Error: the number %d is not enough to be subtracted by %d", b, q)
}
var diff int
diff = b - q
if (diff < b || diff < -q) == (b >= 0 && q <= 0) {
return 0, fmt.Errorf("Math: Subtraction overflow occurred %d - %d", b, q)
}
return diff, nil
}