Commit 7d523aea authored by Adam Reichold's avatar Adam Reichold Committed by Albert Astals Cid

Use GCC instrinsics to perform overflow checking in the gmem allocation functions.

parent 2b4371b4
Pipeline #3712 passed with stage
in 2 minutes and 4 seconds
......@@ -94,12 +94,16 @@ inline void *grealloc_checkoverflow(void *p, size_t size) {
*/
inline bool checkedMultiply(int x, int y, int *z) {
#if __GNUC__ >= 5
return __builtin_smul_overflow(x, y, z);
#else
if (x != 0 && INT_MAX / x < y) {
return true;
}
*z = x * y;
return false;
#endif
}
inline void *gmallocn(int count, int size, bool checkoverflow = false) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment