-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbase_checked.h
More file actions
54 lines (44 loc) · 1.1 KB
/
Copy pathbase_checked.h
File metadata and controls
54 lines (44 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#ifndef LJRE_BASE_CHECKED_H
#define LJRE_BASE_CHECKED_H
#include "base.h"
static inline bool
CheckedAddI64(int64* out, int64 lhs, int64 rhs)
{
return !__builtin_add_overflow(lhs, rhs, out);
}
static inline bool
CheckedAddU64(uint64* out, uint64 lhs, uint64 rhs)
{
return !__builtin_add_overflow(lhs, rhs, out);
}
static inline bool
CheckedAddI32(int32* out, int32 lhs, int32 rhs)
{
return !__builtin_add_overflow(lhs, rhs, out);
}
static inline bool
CheckedAddU32(uint32* out, uint32 lhs, uint32 rhs)
{
return !__builtin_add_overflow(lhs, rhs, out);
}
static inline bool
CheckedSubI64(int64* out, int64 lhs, int64 rhs)
{
return !__builtin_sub_overflow(lhs, rhs, out);
}
static inline bool
CheckedSubI32(int32* out, int32 lhs, int32 rhs)
{
return !__builtin_sub_overflow(lhs, rhs, out);
}
static inline bool
CheckedMulI64(int64* out, int64 lhs, int64 rhs)
{
return !__builtin_mul_overflow(lhs, rhs, out);
}
static inline bool
CheckedMulI32(int32* out, int32 lhs, int32 rhs)
{
return !__builtin_mul_overflow(lhs, rhs, out);
}
#endif //LJRE_BASE_CHECKED_H