.gitignore: add some more IDE / tools related file
[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 6
ae2be88d
SM
7#ifndef BABELTRACE_COMMON_SAFE_H
8#define BABELTRACE_COMMON_SAFE_H
9
91d81473
MJ
10#include <stdbool.h>
11#include <stdint.h>
12
97ebbaa0
PP
13#ifdef __cplusplus
14extern "C" {
15#endif
16
91d81473
MJ
17static inline
18bool bt_safe_to_mul_int64(int64_t a, int64_t b)
19{
20 if (a == 0 || b == 0) {
21 return true;
22 }
23
24 return a < INT64_MAX / b;
25}
26
27static inline
28bool bt_safe_to_mul_uint64(uint64_t a, uint64_t b)
29{
30 if (a == 0 || b == 0) {
31 return true;
32 }
33
34 return a < UINT64_MAX / b;
35}
36
37static inline
38bool bt_safe_to_add_int64(int64_t a, int64_t b)
39{
40 return a <= INT64_MAX - b;
41}
42
43static inline
44bool bt_safe_to_add_uint64(uint64_t a, uint64_t b)
45{
46 return a <= UINT64_MAX - b;
47}
97ebbaa0
PP
48
49#ifdef __cplusplus
50}
51#endif
ae2be88d
SM
52
53#endif /* BABELTRACE_COMMON_SAFE_H */
This page took 0.081729 seconds and 5 git commands to generate.