Botan
2.1.0
Crypto and TLS for C++11
Main Page
Namespaces
Classes
Files
File List
File Members
src
lib
utils
safeint.h
Go to the documentation of this file.
1
/*
2
* Safe(r) Integer Handling
3
* (C) 2016 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7
8
#ifndef BOTAN_UTILS_SAFE_INT_H__
9
#define BOTAN_UTILS_SAFE_INT_H__
10
11
#include <botan/exceptn.h>
12
#include <string>
13
14
namespace
Botan
{
15
16
class
Integer_Overflow_Detected
:
public
Exception
17
{
18
public
:
19
Integer_Overflow_Detected
(
const
std::string& file,
int
line) :
20
Exception
(
"Integer overflow detected at "
+ file +
":"
+
std
::
to_string
(line))
21
{}
22
};
23
24
inline
size_t
checked_add
(
size_t
x,
size_t
y,
const
char
* file,
int
line)
25
{
26
// TODO: use __builtin_x_overflow on GCC and Clang
27
size_t
z = x + y;
28
if
(z < x)
29
{
30
throw
Integer_Overflow_Detected
(file, line);
31
}
32
return
z;
33
}
34
35
#define BOTAN_CHECKED_ADD(x,y) checked_add(x,y,__FILE__,__LINE__)
36
37
}
38
39
#endif
Botan::Exception
Definition:
exceptn.h:21
Botan::Integer_Overflow_Detected::Integer_Overflow_Detected
Integer_Overflow_Detected(const std::string &file, int line)
Definition:
safeint.h:19
Botan::checked_add
size_t checked_add(size_t x, size_t y, const char *file, int line)
Definition:
safeint.h:24
std
Definition:
bigint.h:619
Botan::Integer_Overflow_Detected
Definition:
safeint.h:16
Botan
Definition:
alg_id.cpp:13
Botan::to_string
std::string to_string(const secure_vector< uint8_t > &bytes)
Definition:
stl_util.h:25
Generated on Fri Aug 4 2017 19:29:39 for Botan by
1.8.9.1