Skip to content

Commit 7671bdd

Browse files
yjwxfqdenyeart
authored andcommitted
Update token_contract.go, checking the input params > 0 in function sub().
Signed-off-by: yjwxfq <[email protected]>
1 parent 9a4920d commit 7671bdd

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

token-erc-20/chaincode-go/chaincode/token_contract.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -719,13 +719,15 @@ func checkInitialized(ctx contractapi.TransactionContextInterface) (bool, error)
719719
// sub two number checking for overflow
720720
func sub(b int, q int) (int, error) {
721721

722-
// Check overflow
722+
// sub two number checking
723+
if q <= 0 {
724+
return 0, fmt.Errorf("Error: the subtraction number is %d, it should be greater than 0", q)
725+
}
726+
if b < q {
727+
return 0, fmt.Errorf("Error: the number %d is not enough to be subtracted by %d", b, q)
728+
}
723729
var diff int
724730
diff = b - q
725731

726-
if (diff < b || diff < -q) == (b >= 0 && q <= 0) {
727-
return 0, fmt.Errorf("Math: Subtraction overflow occurred %d - %d", b, q)
728-
}
729-
730732
return diff, nil
731733
}

0 commit comments

Comments
 (0)