Added test for T1 is signed

pull/35/head
Jeffrey Walton 2015-07-29 22:37:36 -04:00
parent d41009f1dc
commit 414b673706
1 changed files with 7 additions and 1 deletions

8
misc.h
View File

@ -381,8 +381,14 @@ inline bool SafeConvert(T1 from, T2 &to)
// Fall through for T1 is unsigned // Fall through for T1 is unsigned
} }
if(from > static_cast<T1>(std::numeric_limits<T2>::max())) // Handle unsigned greater
if(!std::numeric_limits<T1>::is_signed && from > static_cast<T1>(std::numeric_limits<T2>::max())) {
return false; return false;
}
// Handle signed less
else if(from < static_cast<T1>(std::numeric_limits<T2>::min())) {
return false;
}
return true; return true;
} }