Commit 4f1a8639 by Jamie Madill

Add helper functions to determien if addition and mulutiplication of unsigned…

Add helper functions to determien if addition and mulutiplication of unsigned values will cause an overflow. TRAC #23842 Signed-off-by: Geoff Lang Signed-off-by: Shannon Woods
parent 486a1af8
......@@ -496,6 +496,20 @@ T roundUp(const T value, const T alignment)
return value + alignment - 1 - (value - 1) % alignment;
}
template <class T>
inline bool IsUnsignedAdditionSafe(T lhs, T rhs)
{
META_ASSERT(!std::numeric_limits<T>::is_signed);
return (rhs <= std::numeric_limits<T>::max() - lhs);
}
template <class T>
inline bool IsUnsignedMultiplicationSafe(T lhs, T rhs)
{
META_ASSERT(!std::numeric_limits<T>::is_signed);
return (lhs == T(0) || rhs == T(0) || (rhs <= std::numeric_limits<T>::max() / lhs));
}
}
#endif // LIBGLESV2_MATHUTIL_H_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment