returns 1 if the sum of two signed ints is valid (between -2^31 and 2^31-1 inclusive), 0 on overflow.
| 1031 | |
| 1032 | // returns 1 if the sum of two signed ints is valid (between -2^31 and 2^31-1 inclusive), 0 on overflow. |
| 1033 | static int stbi__addints_valid(int a, int b) { |
| 1034 | if ((a >= 0) != (b >= 0)) |
| 1035 | return 1; // a and b have different signs, so no overflow |
| 1036 | if (a < 0 && b < 0) |
| 1037 | return a >= INT_MIN - b; // same as a + b >= INT_MIN; INT_MIN - b cannot overflow since b < 0. |
| 1038 | return a <= INT_MAX - b; |
| 1039 | } |
| 1040 | |
| 1041 | // returns 1 if the product of two signed shorts is valid, 0 on overflow. |
| 1042 | static int stbi__mul2shorts_valid(short a, short b) { |
no outgoing calls
no test coverage detected