#include <safe.hpp>
|
safe | operator+ (const safe &a, const safe &b) |
|
safe | operator- (const safe &a, const safe &b) |
|
safe | operator* (const safe &a, const safe &b) |
|
safe | operator/ (const safe &a, const safe &b) |
|
safe | operator% (const safe &a, const safe &b) |
|
bool | operator== (const safe &a, const safe &b) |
|
bool | operator== (const safe &a, const T &b) |
|
bool | operator== (const T &a, const safe &b) |
|
bool | operator< (const safe &a, const safe &b) |
|
bool | operator< (const safe &a, const T &b) |
|
bool | operator< (const T &a, const safe &b) |
|
bool | operator> (const safe &a, const safe &b) |
|
bool | operator> (const safe &a, const T &b) |
|
bool | operator> (const T &a, const safe &b) |
|
bool | operator!= (const safe &a, const safe &b) |
|
bool | operator!= (const safe &a, const T &b) |
|
bool | operator!= (const T &a, const safe &b) |
|
bool | operator<= (const safe &a, const safe &b) |
|
bool | operator<= (const safe &a, const T &b) |
|
bool | operator<= (const T &a, const safe &b) |
|
bool | operator>= (const safe &a, const safe &b) |
|
bool | operator>= (const safe &a, const T &b) |
|
bool | operator>= (const T &a, const safe &b) |
|
template<typename
T>
struct fc::safe< T >
This type is designed to provide automatic checks for integer overflow and default initialization. It will throw an exception on overflow conditions.
It can only be used on built-in types. In particular, safe<uint128_t> is buggy and should not be used.
Implemented using spec from: https://www.securecoding.cert.org/confluence/display/c/INT32-C.+Ensure+that+operations+on+signed+integers+do+not+result+in+overflow
Definition at line 42 of file variant.hpp.
◆ safe() [1/3]
◆ safe() [2/3]
◆ safe() [3/3]
◆ max()
Definition at line 34 of file safe.hpp.
35 {
36 return std::numeric_limits<T>::max();
37 }
◆ min()
Definition at line 30 of file safe.hpp.
31 {
32 return std::numeric_limits<T>::min();
33 }
◆ operator%=()
Definition at line 119 of file safe.hpp.
120 {
122 return *this;
123 }
◆ operator*=()
Definition at line 109 of file safe.hpp.
110 {
112 return *this;
113 }
◆ operator++() [1/2]
Definition at line 125 of file safe.hpp.
126 {
127 *this += 1;
128 return *this;
129 }
◆ operator++() [2/2]
Definition at line 130 of file safe.hpp.
131 {
133 *this += 1;
134 return bak;
135 }
◆ operator+=()
Definition at line 99 of file safe.hpp.
100 {
102 return *this;
103 }
◆ operator-()
Definition at line 93 of file safe.hpp.
94 {
97 }
#define FC_CAPTURE_AND_THROW(EXCEPTION_TYPE,...)
◆ operator--() [1/2]
Definition at line 137 of file safe.hpp.
138 {
139 *this -= 1;
140 return *this;
141 }
◆ operator--() [2/2]
Definition at line 142 of file safe.hpp.
143 {
145 *this -= 1;
146 return bak;
147 }
◆ operator-=()
Definition at line 104 of file safe.hpp.
105 {
107 return *this;
108 }
◆ operator/=()
Definition at line 114 of file safe.hpp.
115 {
117 return *this;
118 }
◆ operator!= [1/3]
Definition at line 188 of file safe.hpp.
189 {
191 }
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
◆ operator!= [2/3]
◆ operator!= [3/3]
◆ operator%
Definition at line 86 of file safe.hpp.
87 {
89 if(
a.value == std::numeric_limits<T>::min() && b.value == -1 )
FC_CAPTURE_AND_THROW( overflow_exception, (
a)(b) );
90 return safe(
a.value % b.value );
91 }
◆ operator*
Definition at line 52 of file safe.hpp.
53 {
55 {
56 if( b.value > 0 )
57 {
58 if(
a.value > (std::numeric_limits<T>::max() / b.value) )
FC_CAPTURE_AND_THROW( overflow_exception, (
a)(b) );
59 }
60 else
61 {
63 }
64 }
65 else
66 {
67 if( b.value > 0 )
68 {
70 }
71 else
72 {
73 if(
a.value != 0 && b.value < (std::numeric_limits<T>::max() /
a.value) )
FC_CAPTURE_AND_THROW( overflow_exception, (
a)(b) );
74 }
75 }
76
77 return safe(
a.value * b.value );
78 }
file_not_found_exception parse_error_exception invalid_arg_exception invalid_operation_exception key_not_found_exception bad_cast_exception out_of_range_exception canceled_exception assert_exception eof_exception unknown_host_exception null_optional udt_exception aes_exception overflow_exception underflow_exception(divide_by_zero_exception)) namespace detail
◆ operator+
Definition at line 39 of file safe.hpp.
40 {
41 if( b.value > 0 &&
a.value > (std::numeric_limits<T>::max() - b.value) )
FC_CAPTURE_AND_THROW( overflow_exception, (
a)(b) );
43 return safe(
a.value + b.value );
44 }
◆ operator-
Definition at line 45 of file safe.hpp.
46 {
48 if( b.value < 0 &&
a.value > (std::numeric_limits<T>::max() + b.value) )
FC_CAPTURE_AND_THROW( overflow_exception, (
a)(b) );
49 return safe(
a.value - b.value );
50 }
◆ operator/
Definition at line 80 of file safe.hpp.
81 {
83 if(
a.value == std::numeric_limits<T>::min() && b.value == -1 )
FC_CAPTURE_AND_THROW( overflow_exception, (
a)(b) );
84 return safe(
a.value / b.value );
85 }
◆ operator< [1/3]
bool operator< |
( |
const safe< T > & | a, |
|
|
const safe< T > & | b ) |
|
friend |
Definition at line 162 of file safe.hpp.
163 {
164 return a.value < b.value;
165 }
◆ operator< [2/3]
bool operator< |
( |
const safe< T > & | a, |
|
|
const T & | b ) |
|
friend |
◆ operator< [3/3]
bool operator< |
( |
const T & | a, |
|
|
const safe< T > & | b ) |
|
friend |
◆ operator<= [1/3]
bool operator<= |
( |
const safe< T > & | a, |
|
|
const safe< T > & | b ) |
|
friend |
◆ operator<= [2/3]
bool operator<= |
( |
const safe< T > & | a, |
|
|
const T & | b ) |
|
friend |
◆ operator<= [3/3]
bool operator<= |
( |
const T & | a, |
|
|
const safe< T > & | b ) |
|
friend |
◆ operator== [1/3]
bool operator== |
( |
const safe< T > & | a, |
|
|
const safe< T > & | b ) |
|
friend |
Definition at line 149 of file safe.hpp.
150 {
151 return a.value == b.value;
152 }
◆ operator== [2/3]
bool operator== |
( |
const safe< T > & | a, |
|
|
const T & | b ) |
|
friend |
◆ operator== [3/3]
bool operator== |
( |
const T & | a, |
|
|
const safe< T > & | b ) |
|
friend |
◆ operator> [1/3]
bool operator> |
( |
const safe< T > & | a, |
|
|
const safe< T > & | b ) |
|
friend |
Definition at line 175 of file safe.hpp.
176 {
177 return a.value > b.value;
178 }
◆ operator> [2/3]
bool operator> |
( |
const safe< T > & | a, |
|
|
const T & | b ) |
|
friend |
◆ operator> [3/3]
bool operator> |
( |
const T & | a, |
|
|
const safe< T > & | b ) |
|
friend |
◆ operator>= [1/3]
bool operator>= |
( |
const safe< T > & | a, |
|
|
const safe< T > & | b ) |
|
friend |
◆ operator>= [2/3]
bool operator>= |
( |
const safe< T > & | a, |
|
|
const T & | b ) |
|
friend |
◆ operator>= [3/3]
bool operator>= |
( |
const T & | a, |
|
|
const safe< T > & | b ) |
|
friend |
◆ value
The documentation for this struct was generated from the following files: