return 1 if the sum is valid, 0 on overflow. negative terms are considered invalid.
| 999 | // return 1 if the sum is valid, 0 on overflow. |
| 1000 | // negative terms are considered invalid. |
| 1001 | static int stbi__addsizes_valid(int a, int b) |
| 1002 | { |
| 1003 | if (b < 0) return 0; |
| 1004 | // now 0 <= b <= INT_MAX, hence also |
| 1005 | // 0 <= INT_MAX - b <= INTMAX. |
| 1006 | // And "a + b <= INT_MAX" (which might overflow) is the |
| 1007 | // same as a <= INT_MAX - b (no overflow) |
| 1008 | return a <= INT_MAX - b; |
| 1009 | } |
| 1010 | |
| 1011 | // returns 1 if the product is valid, 0 on overflow. |
| 1012 | // negative factors are considered invalid. |
no outgoing calls
no test coverage detected