From 7671bdd7c67889560bee1dd20d40aa30f1d7157e Mon Sep 17 00:00:00 2001 From: yjwxfq <112159687+yjwxfq@users.noreply.github.com> Date: Tue, 20 Jun 2023 16:00:24 +0800 Subject: [PATCH] Update token_contract.go, checking the input params > 0 in function sub(). Signed-off-by: yjwxfq <112159687+yjwxfq@users.noreply.github.com> --- .../chaincode-go/chaincode/token_contract.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/token-erc-20/chaincode-go/chaincode/token_contract.go b/token-erc-20/chaincode-go/chaincode/token_contract.go index 9752fd3c..b13d8095 100644 --- a/token-erc-20/chaincode-go/chaincode/token_contract.go +++ b/token-erc-20/chaincode-go/chaincode/token_contract.go @@ -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 }