With the proposed changes for SafeConvert (see below), I'm wondering if we
should add some asserts for debug builds.
The assert will alert of a potential problem with the conversion, so those
who don't check return values will be made aware of potential problems with
their code.
CRYPTOPP_ASSERT raises a SIGTRAP, so it won't degrade the debugging
experience. Under GDB, the user can press "c" to continue.
**********
template <class T1, class T2>
inline bool SafeConvert(T1 from, T2 &to)
{
// Original code: always perform the assignment
to = (T2)from;
// Check for sign difference
if(std::numeric_limits<T1>::is_signed ^
std::numeric_limits<T2>::is_signed)
{
// Handle T1 is signed
if(std::numeric_limits<T1>::is_signed && from < 0)
return false;
// Fall through for T1 is unsigned
}
if(from > static_cast<T1>(std::numeric_limits<T2>::max()))
return false;
return true;
}
--
--
You received this message because you are subscribed to the "Crypto++ Users"
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at
http://www.cryptopp.com.
---
You received this message because you are subscribed to the Google Groups
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.