mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-27 11:06:50 +01:00
fix(strToInt): overflows #3580
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include "Poco/NumericString.h"
|
||||
#include "Poco/MemoryStream.h"
|
||||
#include "Poco/NumberFormatter.h"
|
||||
#include <limits>
|
||||
|
||||
|
||||
class StringTest: public CppUnit::TestCase
|
||||
@@ -53,12 +54,14 @@ public:
|
||||
void testNumericStringLimit();
|
||||
void testStringToFloatError();
|
||||
void testNumericLocale();
|
||||
void benchmarkStrToFloat();
|
||||
void benchmarkStrToInt();
|
||||
|
||||
void testIntToString();
|
||||
void testFloatToString();
|
||||
|
||||
void conversionBenchmarks();
|
||||
void benchmarkFloatToStr();
|
||||
void benchmarkStrToFloat();
|
||||
void benchmarkStrToInt();
|
||||
|
||||
void testJSONString();
|
||||
|
||||
@@ -128,7 +131,6 @@ private:
|
||||
assertFalse(s == std::numeric_limits<Smaller>::min());
|
||||
assertTrue(Poco::strToInt<Smaller>(val, s, 10));
|
||||
assertTrue (s == std::numeric_limits<Smaller>::min());
|
||||
assertTrue(s == std::numeric_limits<Smaller>::min());
|
||||
--l; val = Poco::NumberFormatter::format(l);
|
||||
assertFalse(Poco::strToInt<Smaller>(val, s, 10));
|
||||
--l; val = Poco::NumberFormatter::format(l);
|
||||
@@ -143,6 +145,21 @@ private:
|
||||
assertFalse(Poco::strToInt<Smaller>(val, s, 10));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void multiplyOverflow()
|
||||
{
|
||||
T m = static_cast<T>(10);
|
||||
T t = 0;
|
||||
T f = std::numeric_limits<T>::max()/m;
|
||||
assertTrue (Poco::safeMultiply(t, f, m));
|
||||
f += 1;
|
||||
assertFalse (Poco::safeMultiply(t, f, m));
|
||||
f = std::numeric_limits<T>::min()/m;
|
||||
assertTrue (Poco::safeMultiply(t, f, m));
|
||||
f -= 1;
|
||||
assertFalse (Poco::safeMultiply(t, f, m));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool parseStream(const std::string& s, T& value)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user