fix(NumberParser): tryParseHex shall not throw, but return boolean

This commit is contained in:
Matej Kenda 2025-02-03 20:36:57 +01:00
parent 6b324b83d4
commit 5b7fbda0cb
3 changed files with 11 additions and 1 deletions

View File

@ -242,7 +242,8 @@ bool strToInt(const char* pStr, I& outResult, short base, char thSep = ',')
if (*pStr == thSep)
{
if (base == 10) continue;
throw Poco::SyntaxException("strToInt: thousand separators only allowed for base 10");
// thousand separators only allowed for base 10
return false;
}
if (result > (limitCheck / base)) return false;
if (!safeMultiply(result, result, base)) return false;

View File

@ -98,6 +98,12 @@ void NumberParserTest::testParse()
assertTrue (NumberParser::parseOct64("0123") == 0123);
#endif
unsigned int u;
assertFalse (NumberParser::tryParseHex("1,000", u));
int i;
assertTrue (NumberParser::tryParse("1,000", i));
#ifndef POCO_NO_FPENVIRONMENT
for (int i = 0; i < 2; ++i)
{

View File

@ -99,6 +99,9 @@ private:
assertTrue (Poco::strToInt("0", result, 010)); assertTrue (result == 0);
assertTrue (Poco::strToInt("000", result, 010)); assertTrue (result == 0);
assertFalse (Poco::strToInt("1,000", result, 0x10));
assertFalse (Poco::strToInt("ABCDEFG", result, 0x10));
}
template <typename Larger, typename Smaller>