mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
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:
parent
9a4920d565
commit
7671bdd7c6
1 changed files with 7 additions and 5 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue