cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[babeltrace.git] / src / common / safe.h
CommitLineData
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
97ebbaa0
PP
10#ifdef __cplusplus
11extern "C" {
12#endif
13
91d81473
MJ
14static inline
15bool bt_safe_to_mul_int64(int64_t a, int64_t b)
16{
17 if (a == 0 || b == 0) {
18 return true;
19 }
20
21 return a < INT64_MAX / b;
22}
23
24static inline
25bool bt_safe_to_mul_uint64(uint64_t a, uint64_t b)
26{
27 if (a == 0 || b == 0) {
28 return true;
29 }
30
31 return a < UINT64_MAX / b;
32}
33
34static inline
35bool bt_safe_to_add_int64(int64_t a, int64_t b)
36{
37 return a <= INT64_MAX - b;
38}
39
40static inline
41bool bt_safe_to_add_uint64(uint64_t a, uint64_t b)
42{
43 return a <= UINT64_MAX - b;
44}
97ebbaa0
PP
45
46#ifdef __cplusplus
47}
48#endif
This page took 0.068164 seconds and 5 git commands to generate.