fix GH #931: make strToInt() more strict in what it accepts

This commit is contained in:
Guenter Obiltschnig
2015-09-09 11:14:29 +02:00
parent 913f2e84b4
commit b083364a94
3 changed files with 17 additions and 59 deletions

View File

@@ -74,28 +74,12 @@ private:
assert(Poco::strToInt("0", result, 10)); assert(result == 0);
assert(Poco::strToInt("000", result, 10)); assert(result == 0);
if (123 < std::numeric_limits<T>::max())
{ assert(Poco::strToInt(" 123 ", result, 10)); assert(result == 123); }
if (123 < std::numeric_limits<T>::max())
{ assert(Poco::strToInt(" 123", result, 10)); assert(result == 123); }
if (123 < std::numeric_limits<T>::max())
{ assert(Poco::strToInt("123 ", result, 10)); assert(result == 123); }
if (std::numeric_limits<T>::is_signed && (-123 > std::numeric_limits<T>::min()))
{ assert(Poco::strToInt("-123", result, 10)); assert(result == -123); }
if (0x123 < std::numeric_limits<T>::max())
{ assert(Poco::strToInt("123", result, 0x10)); assert(result == 0x123); }
if (0x12ab < std::numeric_limits<T>::max())
{ assert(Poco::strToInt("12AB", result, 0x10)); assert(result == 0x12ab); }
if (0x12ab < std::numeric_limits<T>::max())
{ assert(Poco::strToInt("0X12AB", result, 0x10)); assert(result == 0x12ab); }
if (0x12ab < std::numeric_limits<T>::max())
{ assert(Poco::strToInt("0x12AB", result, 0x10)); assert(result == 0x12ab); }
if (0x12ab < std::numeric_limits<T>::max())
{ assert(Poco::strToInt("0x12aB", result, 0x10)); assert(result == 0x12ab); }
if (0x98fe < std::numeric_limits<T>::max())
{ assert(Poco::strToInt("0X98Fe", result, 0x10)); assert(result == 0x98fe); }
if (123 < std::numeric_limits<T>::max())
{ assert(Poco::strToInt("0x0", result, 0x10)); assert(result == 0); }
if (123 < std::numeric_limits<T>::max())
{ assert(Poco::strToInt("00", result, 0x10)); assert(result == 0); }
if (0123 < std::numeric_limits<T>::max())