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

Function stbi__mul2shorts_valid

Source/Utils/stb_image.h:1077–1083  ·  view source on GitHub ↗

returns 1 if the product of two ints fits in a signed short, 0 on overflow.

Source from the content-addressed store, hash-verified

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)
1078{
1079 if (b == 0 || b == -1) return 1; // multiplication by 0 is always 0; check for -1 so SHRT_MIN/b doesn't overflow
1080 if ((a >= 0) == (b >= 0)) return a <= SHRT_MAX/b; // product is positive, so similar to mul2sizes_valid
1081 if (b < 0) return a <= SHRT_MIN / b; // same as a * b >= SHRT_MIN
1082 return a >= SHRT_MIN / b;
1083}
1084
1085// stbi__err - error
1086// stbi__errpf - error returning pointer to float

Callers 2

stbi__jpeg_decode_blockFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected