diff --git a/Foundation/include/Poco/Dynamic/VarHolder.h b/Foundation/include/Poco/Dynamic/VarHolder.h index 0f9cb4910..2116868b8 100644 --- a/Foundation/include/Poco/Dynamic/VarHolder.h +++ b/Foundation/include/Poco/Dynamic/VarHolder.h @@ -398,20 +398,36 @@ protected: private: - template - void POCO_UNUSED checkUpperLimit(const F& from) const - { - if ((sizeof(T) < sizeof(F)) && - (from > static_cast(std::numeric_limits::max()))) + template + void POCO_UNUSED checkUpperLimit(const F& from) const { - throw RangeException("Value too large."); + // casting to type of smaller size AND + // 'from' is greater than 'T' max value + if ((sizeof(T) < sizeof(F)) && + (from > static_cast(std::numeric_limits::max()))) + { + throw RangeException("Value too large."); + } + // casting to type of equal/bigger size AND + // 'F' is signed AND + // 'T' is unsigned AND + // 'from' is negative + else if (std::numeric_limits::is_signed && + !std::numeric_limits::is_signed && from < 0) + { + throw RangeException("Value too small."); + } + // casting to type of equal/bigger size AND + // 'F' is unsigned AND + // 'T' is signed AND + // 'from' is greater than 'T' max value + else if (!std::numeric_limits::is_signed && + std::numeric_limits::is_signed && + static_cast(from) > std::numeric_limits::max()) + { + throw RangeException("Value too large."); + } } - else - if (from > std::numeric_limits::max()) - { - throw RangeException("Value too large."); - } - } template diff --git a/Foundation/testsuite/src/CoreTest.cpp b/Foundation/testsuite/src/CoreTest.cpp index b8a03ca93..ab96e10d3 100644 --- a/Foundation/testsuite/src/CoreTest.cpp +++ b/Foundation/testsuite/src/CoreTest.cpp @@ -79,9 +79,10 @@ namespace { } - NonDefaultConstructible operator=(int val) + NonDefaultConstructible& operator=(int val) { _val = val; + return *this; } bool operator == (const NonDefaultConstructible& other) const