Cleared "comparison between signed and unsigned integer" warning in SafeConvert by providing template specializations

This commit is contained in:
Jeffrey Walton 2015-07-23 18:15:29 -04:00
parent 3fd7a239f0
commit 504ba0ea87

46
misc.h
View File

@ -4,8 +4,9 @@
#include "cryptlib.h"
#include "smartptr.h"
#include "trap.h"
#include <string.h> // for memcpy and memmove
#include <limits> // for numeric_limits
#include <string.h> // for memcpy and memmove
#include <iosfwd> // for std::streamsize
#include <limits> // 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,std::istream::off_type>(lword from, std::istream::off_type &to)
{
if(from > static_cast<lword>(std::numeric_limits<std::istream::off_type>::max()))
return false;
return true;
}
#endif
// files.cpp, line 235
template<>
inline bool SafeConvert<size_t,std::streamsize>(size_t from, std::streamsize &to)
{
to = (std::streamsize)from;
if(from > static_cast<size_t>(std::numeric_limits<std::streamsize>::max()))
return false;
return true;
}
// files.cpp, line 366
template<>
inline bool SafeConvert<long long unsigned int,long int>(long long unsigned int from, long int &to)
{
to = (long int)from;
if(from > static_cast<long long unsigned int>(std::numeric_limits<long int>::max()))
return false;
return true;
}
// nbtheory.cpp, line 315
template<>
inline bool SafeConvert<long int,word>(long int from, word &to)
{
to = (word)from;
if(from > static_cast<long int>(std::numeric_limits<word>::max()))
return false;
return true;
}
inline size_t BitsToBytes(size_t bitCount)
{
return ((bitCount+7)/(8));