Tor
0.4.9.2-alpha-dev
Toggle main menu visibility
Main Page
Related Pages
Modules
Data Structures
Data Structures
Data Structure Index
Data Fields
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
Functions
Variables
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
Enumerator
Files
File List
Globals
All
_
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Functions
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
Variables
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
z
Typedefs
b
c
d
f
g
h
l
m
n
o
p
r
s
v
Enumerations
a
b
c
d
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
Enumerator
a
b
c
d
e
g
h
i
m
n
o
p
q
r
s
t
v
w
Macros
_
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
r
s
t
u
v
w
x
•
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Modules
Pages
lib
intmath
addsub.c
Go to the documentation of this file.
1
/* Copyright (c) 2003-2004, Roger Dingledine
2
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3
* Copyright (c) 2007-2021, The Tor Project, Inc. */
4
/* See LICENSE for licensing information */
5
6
/**
7
* \file addsub.c
8
*
9
* \brief Helpers for addition and subtraction.
10
*
11
* Currently limited to non-wrapping (saturating) addition.
12
**/
13
14
#include "
lib/intmath/addsub.h
"
15
#include "
lib/cc/compat_compiler.h
"
16
17
/* Helper: safely add two uint32_t's, capping at UINT32_MAX rather
18
* than overflow */
19
uint32_t
20
tor_add_u32_nowrap(uint32_t a, uint32_t b)
21
{
22
/* a+b > UINT32_MAX check, without overflow */
23
if
(PREDICT_UNLIKELY(a > UINT32_MAX - b)) {
24
return
UINT32_MAX;
25
}
else
{
26
return
a+b;
27
}
28
}
addsub.h
Header for addsub.c.
compat_compiler.h
Utility macros to handle different features and behavior in different compilers.
Generated by
1.9.4