From 504ba0ea874baa65229a3d7b74b48ee5beed2679 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Thu, 23 Jul 2015 18:15:29 -0400 Subject: [PATCH] Cleared "comparison between signed and unsigned integer" warning in SafeConvert by providing template specializations --- misc.h | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/misc.h b/misc.h index 15206561..0349324f 100644 --- a/misc.h +++ b/misc.h @@ -4,8 +4,9 @@ #include "cryptlib.h" #include "smartptr.h" #include "trap.h" -#include // for memcpy and memmove -#include // for numeric_limits +#include // for memcpy and memmove +#include // for std::streamsize +#include // for std::numeric_limits #ifdef _MSC_VER #if _MSC_VER >= 1400 @@ -367,6 +368,47 @@ inline bool SafeConvert(T1 from, T2 &to) return true; } +#if 0 +// files.cpp, line 175 +template<> +inline bool SafeConvert(lword from, std::istream::off_type &to) +{ + if(from > static_cast(std::numeric_limits::max())) + return false; + return true; +} +#endif + +// files.cpp, line 235 +template<> +inline bool SafeConvert(size_t from, std::streamsize &to) +{ + to = (std::streamsize)from; + if(from > static_cast(std::numeric_limits::max())) + return false; + return true; +} + +// files.cpp, line 366 +template<> +inline bool SafeConvert(long long unsigned int from, long int &to) +{ + to = (long int)from; + if(from > static_cast(std::numeric_limits::max())) + return false; + return true; +} + +// nbtheory.cpp, line 315 +template<> +inline bool SafeConvert(long int from, word &to) +{ + to = (word)from; + if(from > static_cast(std::numeric_limits::max())) + return false; + return true; +} + inline size_t BitsToBytes(size_t bitCount) { return ((bitCount+7)/(8));