Commit | Line | Data |
---|---|---|
0235b0db MJ |
1 | /* |
2 | * SPDX-License-Identifier: MIT | |
3 | * | |
4 | * Copyright 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
5 | */ | |
91d81473 MJ |
6 | |
7 | #include <stdbool.h> | |
8 | #include <stdint.h> | |
9 | ||
10 | static inline | |
11 | bool bt_safe_to_mul_int64(int64_t a, int64_t b) | |
12 | { | |
13 | if (a == 0 || b == 0) { | |
14 | return true; | |
15 | } | |
16 | ||
17 | return a < INT64_MAX / b; | |
18 | } | |
19 | ||
20 | static inline | |
21 | bool bt_safe_to_mul_uint64(uint64_t a, uint64_t b) | |
22 | { | |
23 | if (a == 0 || b == 0) { | |
24 | return true; | |
25 | } | |
26 | ||
27 | return a < UINT64_MAX / b; | |
28 | } | |
29 | ||
30 | static inline | |
31 | bool bt_safe_to_add_int64(int64_t a, int64_t b) | |
32 | { | |
33 | return a <= INT64_MAX - b; | |
34 | } | |
35 | ||
36 | static inline | |
37 | bool bt_safe_to_add_uint64(uint64_t a, uint64_t b) | |
38 | { | |
39 | return a <= UINT64_MAX - b; | |
40 | } |