returns 1 if the sum of two signed ints is valid (between -2^31 and 2^31-1 inclusive), 0 on overflow.
| 1067 | |
| 1068 | // returns 1 if the sum of two signed ints is valid (between -2^31 and 2^31-1 inclusive), 0 on overflow. |
| 1069 | static int stbi__addints_valid(int a, int b) |
| 1070 | { |
| 1071 | if ((a >= 0) != (b >= 0)) return 1; // a and b have different signs, so no overflow |
| 1072 | if (a < 0 && b < 0) return a >= INT_MIN - b; // same as a + b >= INT_MIN; INT_MIN - b cannot overflow since b < 0. |
| 1073 | return a <= INT_MAX - b; |
| 1074 | } |
| 1075 | |
| 1076 | // returns 1 if the product of two ints fits in a signed short, 0 on overflow. |
| 1077 | static int stbi__mul2shorts_valid(int a, int b) |
no outgoing calls
no test coverage detected