LibFixedMath functions fail to catch a number of overflows
The `__add()`, `__mul()`, and `__div()` functions perform arithmetic on 256-bit signed integers, and they all miss some specific overflows.\\nAddition Overflows\\n```\\n/// @dev Adds two numbers, reverting on overflow.\\nfunction \\_add(int256 a, int256 b) private pure returns (int256 c) {\\n    c = a + b;\\n    if (c > 0 && a < 0 && b < 0) {\\n        LibRichErrors.rrevert(LibFixedMathRichErrors.BinOpError(\\n            LibFixedMathRichErrors.BinOpErrorCodes.SUBTRACTION\\_OVERFLOW,\\n            a,\\n            b\\n        ));\\n    }\\n    if (c < 0 && a > 0 && b > 0) {\\n        LibRichErrors.rrevert(LibFixedMathRichErrors.BinOpError(\\n            LibFixedMathRichErrors.BinOpErrorCodes.ADDITION\\_OVERFLOW,\\n            a,\\n            b\\n        ));\\n    }\\n}\\n```\\n\\nThe two overflow conditions it tests for are:\\nAdding two positive numbers shouldn't result in a negative number.\\nAdding two negative numbers shouldn't result in a positive number.\\n`__add(-2**255, -2**255)` returns `0` without reverting because the overflow didn't match either of the above conditions.\\nMultiplication Overflows\\n```\\n/// @dev Returns the multiplication two numbers, reverting on overflow.\\nfunction \\_mul(int256 a, int256 b) private pure returns (int256 c) {\\n    if (a == 0) {\\n        return 0;\\n    }\\n    c = a \\* b;\\n    if (c / a != b) {\\n        LibRichErrors.rrevert(LibFixedMathRichErrors.BinOpError(\\n            LibFixedMathRichErrors.BinOpErrorCodes.MULTIPLICATION\\_OVERFLOW,\\n            a,\\n            b\\n        ));\\n    }\\n}\\n```\\n\\nThe function checks via division for most types of overflows, but it fails to catch one particular case. `__mul(-2**255, -1)` returns `-2**255` without error.\\nDivision Overflows\\n```\\n/// @dev Returns the division of two numbers, reverting on division by zero.\\nfunction \\_div(int256 a, int256 b) private pure returns (int256 c) {\\n    if (b == 0) {\\n        LibRichErrors.rrevert(LibFixedMathRichErrors.BinOpError(\\n            LibFixedMathRichErrors.BinOpErrorCodes.DIVISION\\_BY\\_ZERO,\\n            a,\\n            b\\n        ));\\n    }\\n    c = a / b;\\n}\\n```\\n\\nIt does not check for overflow. Due to this, `__div(-2**255, -1)` erroneously returns `-2**255`.
For addition, the specific case of `__add(-2**255, -2**255)` can be detected by using a `>= 0` check instead of `> 0`, but the below seems like a clearer check for all cases:\\n```\\n// if b is negative, then the result should be less than a\\nif (b < 0 && c >= a) { /\\* subtraction overflow \\*/ }\\n\\n// if b is positive, then the result should be greater than a\\nif (b > 0 && c <= a) { /\\* addition overflow \\*/ }\\n```\\n\\nFor multiplication and division, the specific values of `-2**255` and `-1` are the only missing cases, so that can be explicitly checked in the `__mul()` and `__div()` functions.
```\\n/// @dev Adds two numbers, reverting on overflow.\\nfunction \\_add(int256 a, int256 b) private pure returns (int256 c) {\\n    c = a + b;\\n    if (c > 0 && a < 0 && b < 0) {\\n        LibRichErrors.rrevert(LibFixedMathRichErrors.BinOpError(\\n            LibFixedMathRichErrors.BinOpErrorCodes.SUBTRACTION\\_OVERFLOW,\\n            a,\\n            b\\n        ));\\n    }\\n    if (c < 0 && a > 0 && b > 0) {\\n        LibRichErrors.rrevert(LibFixedMathRichErrors.BinOpError(\\n            LibFixedMathRichErrors.BinOpErrorCodes.ADDITION\\_OVERFLOW,\\n            a,\\n            b\\n        ));\\n    }\\n}\\n```\\n