Exiv2
Classes | Functions
Safe::Internal Namespace Reference

Helper functions for providing integer overflow checks. More...

Classes

struct  enable_if
 Helper struct for SFINAE, from C++11. More...
 
struct  enable_if< true, T >
 Specialization of enable_if for the case B == true. More...
 
struct  is_signed
 Helper struct to determine whether a type is signed or unsigned. More...
 

Functions

template<typename T >
bool ::type fallback_add_overflow (T summand_1, T summand_2, T &result)
 

Detailed Description

Helper functions for providing integer overflow checks.

This namespace contains internal helper functions fallback_$op_overflow and builtin_$op_overflow (where $op is an arithmetic operation like add, subtract, etc.). Both provide the following interface:

bool fallback/builtin_$op_overflow(T first, T second, T& result);

where T is an integer type.

Each function performs checks whether first $op second can be safely performed without overflows. If yes, the result is saved in result and false is returned. Otherwise true is returned and the contents of result are unspecified.

fallback_$op_overflow implements a portable but slower overflow check. builtin_$op_overflow uses compiler builtins (when available) and should be faster. As builtins are not available for all types, builtin_$op_overflow falls back to fallback_$op_overflow when no builtin is available.