mirror of
https://github.com/pocoproject/poco.git
synced 2025-11-25 15:19:21 +01:00
Merge pull request #433 from siemens/numparser
NumberParser::parseUnsigned should not parse negative numbers
This commit is contained in:
@@ -110,6 +110,8 @@ bool strToInt(const char* pStr, I& result, short base, char thSep = ',')
|
|||||||
char sign = 1;
|
char sign = 1;
|
||||||
if ((base == 10) && (*pStr == '-'))
|
if ((base == 10) && (*pStr == '-'))
|
||||||
{
|
{
|
||||||
|
// Unsigned types can't be negative so abort parsing
|
||||||
|
if (std::numeric_limits<I>::min() >= 0) return false;
|
||||||
sign = -1;
|
sign = -1;
|
||||||
++pStr;
|
++pStr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -272,6 +272,12 @@ void NumberParserTest::testParseError()
|
|||||||
failmsg("must throw SyntaxException");
|
failmsg("must throw SyntaxException");
|
||||||
} catch (SyntaxException&) { }
|
} catch (SyntaxException&) { }
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
NumberParser::parseUnsigned("-123");
|
||||||
|
failmsg("must throw SyntaxException");
|
||||||
|
} catch (SyntaxException&) { }
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NumberParser::parseHex("z23");
|
NumberParser::parseHex("z23");
|
||||||
|
|||||||
Reference in New Issue
Block a user