[safe_op] Simplified unsigned int overflow check

Simply check for overflows after the addition, as no undefined behavior can
occur here.
This commit is contained in:
Dan Čermák 2018-03-08 00:34:14 +01:00
parent 31b96b58e7
commit 684c8c89de

View File

@ -204,12 +204,8 @@ namespace Safe
*/
static bool add(T summand_1, T summand_2, T& result)
{
if (summand_1 > std::numeric_limits<T>::max() - summand_2) {
return true;
} else {
result = summand_1 + summand_2;
return false;
}
result = summand_1 + summand_2;
return result < summand_1;
}
};