MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / stbi__addints_valid

Function stbi__addints_valid

Source/Utils/stb_image.h:1069–1074  ·  view source on GitHub ↗

returns 1 if the sum of two signed ints is valid (between -2^31 and 2^31-1 inclusive), 0 on overflow.

Source from the content-addressed store, hash-verified

1067
1068// returns 1 if the sum of two signed ints is valid (between -2^31 and 2^31-1 inclusive), 0 on overflow.
1069static 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.
1077static int stbi__mul2shorts_valid(int a, int b)

Callers 2

stbi__jpeg_decode_blockFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected