mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-16 19:54:38 +01:00
Wrong limit check in Poco::Dynamic::Var #996
This commit is contained in:
parent
848d510fae
commit
12f61b8ccf
@ -332,8 +332,8 @@ protected:
|
||||
template <typename F, typename T>
|
||||
void convertToSmallerUnsigned(const F& from, T& to) const
|
||||
/// This function is meant for converting unsigned integral data types,
|
||||
/// from larger to smaller type. Since lower limit is always 0 for unsigned types,
|
||||
/// only the upper limit is checked, thus saving some cycles compared to the signed
|
||||
/// from larger to smaller type. Since lower limit is always 0 for unsigned types,
|
||||
/// only the upper limit is checked, thus saving some cycles compared to the signed
|
||||
/// version of the function. If the value to be converted is smaller than
|
||||
/// the maximum value for the target type, the conversion is performed.
|
||||
{
|
||||
@ -349,8 +349,8 @@ protected:
|
||||
template <typename F, typename T>
|
||||
void convertSignedToUnsigned(const F& from, T& to) const
|
||||
/// This function is meant for converting signed integral data types to
|
||||
/// unsigned data types. Negative values can not be converted and if one is
|
||||
/// encountered, RangeException is thrown.
|
||||
/// unsigned data types. Negative values can not be converted and if one
|
||||
/// is encountered, RangeException is thrown.
|
||||
/// If upper limit is within the target data type limits, the conversion is performed.
|
||||
{
|
||||
poco_static_assert (std::numeric_limits<F>::is_specialized);
|
||||
@ -367,8 +367,8 @@ protected:
|
||||
template <typename F, typename T>
|
||||
void convertSignedFloatToUnsigned(const F& from, T& to) const
|
||||
/// This function is meant for converting floating point data types to
|
||||
/// unsigned integral data types. Negative values can not be converted and if one is
|
||||
/// encountered, RangeException is thrown.
|
||||
/// unsigned integral data types. Negative values can not be converted and if one
|
||||
/// is encountered, RangeException is thrown.
|
||||
/// If upper limit is within the target data type limits, the conversion is performed.
|
||||
{
|
||||
poco_static_assert (std::numeric_limits<F>::is_specialized);
|
||||
@ -386,8 +386,8 @@ protected:
|
||||
template <typename F, typename T>
|
||||
void convertUnsignedToSigned(const F& from, T& to) const
|
||||
/// This function is meant for converting unsigned integral data types to
|
||||
/// unsigned data types. Negative values can not be converted and if one is
|
||||
/// encountered, RangeException is thrown.
|
||||
/// signed integral data types. Negative values can not be converted and if one
|
||||
/// is encountered, RangeException is thrown.
|
||||
/// If upper limit is within the target data type limits, the conversion is performed.
|
||||
{
|
||||
poco_static_assert (std::numeric_limits<F>::is_specialized);
|
||||
@ -395,7 +395,7 @@ protected:
|
||||
poco_static_assert (!std::numeric_limits<F>::is_signed);
|
||||
poco_static_assert (std::numeric_limits<T>::is_signed);
|
||||
|
||||
checkUpperLimit<F,T>(from);
|
||||
checkUpperLimit<F,T>(from);
|
||||
to = static_cast<T>(from);
|
||||
}
|
||||
|
||||
@ -409,7 +409,7 @@ private:
|
||||
throw RangeException("Value too large.");
|
||||
}
|
||||
else
|
||||
if (static_cast<T>(from) > std::numeric_limits<T>::max())
|
||||
if (from > std::numeric_limits<T>::max())
|
||||
{
|
||||
throw RangeException("Value too large.");
|
||||
}
|
||||
|
@ -54,8 +54,9 @@ endif
|
||||
|
||||
COMMONFLAGS += -Wno-unused-variable
|
||||
|
||||
ifneq (,$(findstring g++,$(CXX)))
|
||||
ifeq ('g++',$(findstring 'g++','$(CXX)'))
|
||||
COMMONFLAGS += -Wno-unused-but-set-variable
|
||||
#$(error $(findstring g++,$(CXX)))
|
||||
endif
|
||||
|
||||
ifeq ($(LINKMODE),SHARED)
|
||||
|
@ -133,9 +133,17 @@ private:
|
||||
assert (!std::numeric_limits<TU>::is_signed);
|
||||
|
||||
TS iMin = std::numeric_limits<TS>::min();
|
||||
Poco::Dynamic::Var da = iMin;
|
||||
try { TU i; i = da.convert<TU>(); fail("must fail"); }
|
||||
Poco::Dynamic::Var dMin = iMin;
|
||||
try { TU i; i = dMin.convert<TU>(); fail("must fail"); }
|
||||
catch (Poco::RangeException&) {}
|
||||
|
||||
if(sizeof(TS) == sizeof(TU))
|
||||
{
|
||||
TU iMax = std::numeric_limits<TU>::max();
|
||||
Poco::Dynamic::Var dMax = iMax;
|
||||
try { TS i; i = dMax.convert<TS>(); fail("must fail"); }
|
||||
catch (Poco::RangeException&) {}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename TL, typename TS>
|
||||
|
Loading…
Reference in New Issue
Block a user