Exiv2
|
Overload of fallback_add_overflow for signed integers. More...
#include <safe_op.hpp>
Static Public Member Functions | |
static bool | add (T summand_1, T summand_2, T &result) |
Adds the two summands only if no overflow occurs. More... | |
Overload of fallback_add_overflow for signed integers.
|
inlinestatic |
Adds the two summands only if no overflow occurs.
This function performs a check if summand_1 + summand_2 would overflow and returns true in that case. If no overflow occurs, the sum is saved in result and false is returned.
The check for an overflow is performed before the addition to ensure that no undefined behavior occurs. The value in result is only valid when the function returns false.
Further information: https://wiki.sei.cmu.edu/confluence/display/c/INT32-C.+Ensure+that+operations+on+signed+integers+do+not+result+in+overflow