mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
Update token_contract.go, modify the overflow judgment condition for function sub().
The general overflow judgment condition for function sub is not in every case. The judgment result is wrong in the condition of b < 0 && q >=0 for example, b = -3, q = 2, diff = -5, it's not overflow, but if (diff > b) == (b >= 0 && q >= 0) wil be true. for another example, b = -3, q = maxint, b-q is overflow, but if (diff > b) == (b >= 0 && q >= 0) wil be false. Signed-off-by: yjwxfq <112159687+yjwxfq@users.noreply.github.com>
This commit is contained in:
parent
bc3a6bfa05
commit
9a4920d565
1 changed files with 1 additions and 1 deletions
|
|
@ -723,7 +723,7 @@ func sub(b int, q int) (int, error) {
|
||||||
var diff int
|
var diff int
|
||||||
diff = b - q
|
diff = b - q
|
||||||
|
|
||||||
if (diff > b) == (b >= 0 && q >= 0) {
|
if (diff < b || diff < -q) == (b >= 0 && q <= 0) {
|
||||||
return 0, fmt.Errorf("Math: Subtraction overflow occurred %d - %d", b, q)
|
return 0, fmt.Errorf("Math: Subtraction overflow occurred %d - %d", b, q)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue