Move to kernel style SPDX license identifiers
[babeltrace.git] / src / common / safe.h
... / ...
CommitLineData
1/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 */
6
7#include <stdbool.h>
8#include <stdint.h>
9
10static inline
11bool 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
20static inline
21bool 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
30static inline
31bool bt_safe_to_add_int64(int64_t a, int64_t b)
32{
33 return a <= INT64_MAX - b;
34}
35
36static inline
37bool bt_safe_to_add_uint64(uint64_t a, uint64_t b)
38{
39 return a <= UINT64_MAX - b;
40}
This page took 0.022378 seconds and 4 git commands to generate.