X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcommon%2Fsafe.h;fp=src%2Fcommon%2Fsafe.h;h=26df90a48f5105e7090e57f776598ab04b9cf08d;hb=91d8147391efdc4d42cc4e1c171a65c0372a008f;hp=0000000000000000000000000000000000000000;hpb=4e87f509dec8aed765d6b6b4c868be65b8580c37;p=babeltrace.git diff --git a/src/common/safe.h b/src/common/safe.h new file mode 100644 index 00000000..26df90a4 --- /dev/null +++ b/src/common/safe.h @@ -0,0 +1,35 @@ + +#include +#include + +static inline +bool bt_safe_to_mul_int64(int64_t a, int64_t b) +{ + if (a == 0 || b == 0) { + return true; + } + + return a < INT64_MAX / b; +} + +static inline +bool bt_safe_to_mul_uint64(uint64_t a, uint64_t b) +{ + if (a == 0 || b == 0) { + return true; + } + + return a < UINT64_MAX / b; +} + +static inline +bool bt_safe_to_add_int64(int64_t a, int64_t b) +{ + return a <= INT64_MAX - b; +} + +static inline +bool bt_safe_to_add_uint64(uint64_t a, uint64_t b) +{ + return a <= UINT64_MAX - b; +}