Cleanup: remove private babeltrace.h
[babeltrace.git] / src / common / safe.h
CommitLineData
91d81473
MJ
1
2#include <stdbool.h>
3#include <stdint.h>
4
5static inline
6bool bt_safe_to_mul_int64(int64_t a, int64_t b)
7{
8 if (a == 0 || b == 0) {
9 return true;
10 }
11
12 return a < INT64_MAX / b;
13}
14
15static inline
16bool bt_safe_to_mul_uint64(uint64_t a, uint64_t b)
17{
18 if (a == 0 || b == 0) {
19 return true;
20 }
21
22 return a < UINT64_MAX / b;
23}
24
25static inline
26bool bt_safe_to_add_int64(int64_t a, int64_t b)
27{
28 return a <= INT64_MAX - b;
29}
30
31static inline
32bool bt_safe_to_add_uint64(uint64_t a, uint64_t b)
33{
34 return a <= UINT64_MAX - b;
35}
This page took 0.023517 seconds and 4 git commands to generate.