Fix RoundUpToMultipleOf (Issue 360)

Thanks to Boldizsár Lipka
pull/363/head
Jeffrey Walton 2017-01-10 22:05:53 -05:00
parent bccc6443c4
commit 781e63ba7c
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
1 changed files with 1 additions and 1 deletions

2
misc.h
View File

@ -904,7 +904,7 @@ inline T1 RoundDownToMultipleOf(const T1 &n, const T2 &m)
template <class T1, class T2> template <class T1, class T2>
inline T1 RoundUpToMultipleOf(const T1 &n, const T2 &m) inline T1 RoundUpToMultipleOf(const T1 &n, const T2 &m)
{ {
if (n > (SIZE_MAX/sizeof(T1))-m-1) if (std::numeric_limits<T1>::max() - m + 1 < n)
throw InvalidArgument("RoundUpToMultipleOf: integer overflow"); throw InvalidArgument("RoundUpToMultipleOf: integer overflow");
return RoundDownToMultipleOf(T1(n+m-1), m); return RoundDownToMultipleOf(T1(n+m-1), m);
} }