1 #ifndef RZ_TYPES_OVERFLOW_H
2 #define RZ_TYPES_OVERFLOW_H
11 #define SZT_ADD_OVFCHK(x, y) ((SIZE_MAX - (x)) < (y))
12 #define SSZT_ADD_OVFCHK(a, x) ((((x) > 0) && ((a) > SSIZE_MAX - (x))) || (((x) < 0) && (a) < SSIZE_MIN - (x)))
13 #define UT64_ADD_OVFCHK(x, y) ((UT64_MAX - (x)) < (y))
14 #define ST64_ADD_OVFCHK(a, x) ((((x) > 0) && ((a) > ST64_MAX - (x))) || (((x) < 0) && (a) < ST64_MIN - (x)))
15 #define UT32_ADD_OVFCHK(x, y) ((UT32_MAX - (x)) < (y))
16 #define ST32_ADD_OVFCHK(a, x) ((((x) > 0) && ((a) > ST32_MAX - (x))) || (((x) < 0) && (a) < ST32_MIN - (x)))
17 #define UT16_ADD_OVFCHK(x, y) ((UT16_MAX - (x)) < (y))
18 #define ST16_ADD_OVFCHK(a, b) ((((b) > 0) && ((a) > ST16_MAX - (b))) || (((b) < 0) && ((a) < ST16_MIN - (b))))
19 #define UT8_ADD_OVFCHK(x, y) ((UT8_MAX - (x)) < (y))
20 #define ST8_ADD_OVFCHK(a, x) ((((x) > 0) && ((a) > ST8_MAX - (x))) || ((x) < 0 && (a) < ST8_MIN - (x)))
25 #define SZT_SUB_OVFCHK(a, b) SZT_ADD_OVFCHK(a, -(b))
26 #define SSZT_SUB_OVFCHK(a, b) SSZT_ADD_OVFCHK(a, -(b))
27 #define UT64_SUB_OVFCHK(a, b) UT64_ADD_OVFCHK(a, -(b))
28 #define ST64_SUB_OVFCHK(a, b) ST64_ADD_OVFCHK(a, -(b))
29 #define UT32_SUB_OVFCHK(a, b) UT32_ADD_OVFCHK(a, -(b))
30 #define ST32_SUB_OVFCHK(a, b) ST32_ADD_OVFCHK(a, -(b))
31 #define UT16_SUB_OVFCHK(a, b) UT16_ADD_OVFCHK(a, -(b))
32 #define ST16_SUB_OVFCHK(a, b) ST16_ADD_OVFCHK(a, -(b))
33 #define UT8_SUB_OVFCHK(a, b) UT8_ADD_OVFCHK(a, -(b))
34 #define ST8_SUB_OVFCHK(a, b) ST8_ADD_OVFCHK(a, -(b))
37 #define UNSIGNED_MUL_OVERFLOW_CHECK(overflow_name, type_base, type_min, type_max) \
38 static inline bool overflow_name(type_base a, type_base b) { \
39 return (a > 0 && b > 0 && a > type_max / b); \
42 #define SIGNED_MUL_OVERFLOW_CHECK(overflow_name, type_base, type_min, type_max) \
43 static inline bool overflow_name(type_base a, type_base b) { \
46 return a > type_max / b; \
48 return b < type_min / a; \
51 return a < type_min / b; \
53 return a && b < type_max / a; \
56 #define SIGNED_DIV_OVERFLOW_CHECK(overflow_name, type_base, type_mid, type_max) \
57 static inline bool overflow_name(type_base a, type_base b) { \
58 return (!b || (a == type_mid && b == type_max)); \
60 #define UNSIGNED_DIV_OVERFLOW_CHECK(overflow_name, type_base, type_min, type_max) \
61 static inline bool overflow_name(type_base a, type_base b) { \
#define UNSIGNED_MUL_OVERFLOW_CHECK(overflow_name, type_base, type_min, type_max)
#define SIGNED_DIV_OVERFLOW_CHECK(overflow_name, type_base, type_mid, type_max)
#define UNSIGNED_DIV_OVERFLOW_CHECK(overflow_name, type_base, type_min, type_max)
#define SIGNED_MUL_OVERFLOW_CHECK(overflow_name, type_base, type_min, type_max)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()