From d3b2c03e4e59fa170bb9575d7bf935f0f1f0bb24 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sat, 25 Jul 2015 02:06:52 -0400 Subject: [PATCH] Added missing specialization for i386. Added comment on why we were specializing --- misc.h | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/misc.h b/misc.h index f478f563..4cdc2de8 100644 --- a/misc.h +++ b/misc.h @@ -360,6 +360,7 @@ inline T Crop(T value, size_t size) return value; } +// Provide specializations of these as required. It avoids the signed/unsigned mismatch. template inline bool SafeConvert(T1 from, T2 &to) { @@ -369,17 +370,6 @@ 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) @@ -400,12 +390,32 @@ inline bool SafeConvert(long long unsigned int return true; } +// files.cpp, line 366 +template<> +inline bool SafeConvert(long long unsigned int from, long long int &to) +{ + to = (long 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())) + if(from < 0 || from > static_cast(std::numeric_limits::max())) + return false; + return true; +} + +// nbtheory.cpp, line 315 +template<> +inline bool SafeConvert(int from, unsigned int &to) +{ + to = (word)from; + if(from < 0 || from > static_cast(std::numeric_limits::max())) return false; return true; }