# Check Overflow

Extra caution should be exercised when performing addition, subtraction, or multiplication operations to ensure no overflow occurs. If there's potential for an overflow, use the operators that return a gtBool value indicating whether an overflow has taken place.\\

<mark style="color:red;">**Avoid:**</mark>

```solidity
contract AvoidContract {
    function addingGtWithoutChecking(gtUint16 lhs, gtUint16 rhs) public {
        gtUint16 addResult = MpcCore.add(lhs, rhs);
        return addResult;
    }
}
```

<mark style="color:blue;">**Do**</mark> <mark style="color:blue;"></mark><mark style="color:blue;">:</mark> <mark style="color:blue;">Check the overflow bit with mux, return zero if an on overflow accrued.</mark>

```solidity
contract goodContract {
    function addingGtReturnZeroOnOverFlow(gtUint16 lhs, gtUint16 rhs) public {
        (gtBool isOverflowed, gtUint16 tempAddResult) = MpcCore.checkedAddWithOverflowBit(lhs, rhs);
        gtUint16 gtZero = MpcCore.setPublic16(0)
        addResult = MpcCore.mux(isOverflow, gtZero, tempAddResult);
        return addResult;
    }
}
```
