From df855c88b7cdf239e32d0573e2db9bd3432a0a19 Mon Sep 17 00:00:00 2001 From: Guenter Obiltschnig Date: Mon, 24 Oct 2016 09:41:49 +0200 Subject: [PATCH] fixed GH #1462: AbstractConfiguration::getUInt does not parse hex numbers --- Util/include/Poco/Util/AbstractConfiguration.h | 2 +- Util/src/AbstractConfiguration.cpp | 18 +++++++++--------- .../src/AbstractConfigurationTest.cpp | 3 +++ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Util/include/Poco/Util/AbstractConfiguration.h b/Util/include/Poco/Util/AbstractConfiguration.h index 4cc09cf07..d1e746793 100644 --- a/Util/include/Poco/Util/AbstractConfiguration.h +++ b/Util/include/Poco/Util/AbstractConfiguration.h @@ -346,7 +346,7 @@ protected: /// implementation throws a Poco::NotImplementedException. static int parseInt(const std::string& value); - static int parseUInt(const std::string& value); + static unsigned parseUInt(const std::string& value); #if defined(POCO_HAVE_INT64) diff --git a/Util/src/AbstractConfiguration.cpp b/Util/src/AbstractConfiguration.cpp index d9981ead2..6b4f07f37 100644 --- a/Util/src/AbstractConfiguration.cpp +++ b/Util/src/AbstractConfiguration.cpp @@ -147,7 +147,7 @@ unsigned AbstractConfiguration::getUInt(const std::string& key) const std::string value; if (getRaw(key, value)) - return NumberParser::parseUnsigned(internalExpand(value)); + return parseUInt(internalExpand(value)); else throw NotFoundException(key); } @@ -159,7 +159,7 @@ unsigned AbstractConfiguration::getUInt(const std::string& key, unsigned default std::string value; if (getRaw(key, value)) - return NumberParser::parseUnsigned(internalExpand(value)); + return parseUInt(internalExpand(value)); else return defaultValue; } @@ -174,7 +174,7 @@ Int64 AbstractConfiguration::getInt64(const std::string& key) const std::string value; if (getRaw(key, value)) - return NumberParser::parse64(internalExpand(value)); + return parseInt64(internalExpand(value)); else throw NotFoundException(key); } @@ -186,7 +186,7 @@ Int64 AbstractConfiguration::getInt64(const std::string& key, Int64 defaultValue std::string value; if (getRaw(key, value)) - return NumberParser::parse64(internalExpand(value)); + return parseInt64(internalExpand(value)); else return defaultValue; } @@ -198,7 +198,7 @@ UInt64 AbstractConfiguration::getUInt64(const std::string& key) const std::string value; if (getRaw(key, value)) - return NumberParser::parseUnsigned64(internalExpand(value)); + return parseUInt64(internalExpand(value)); else throw NotFoundException(key); } @@ -210,7 +210,7 @@ UInt64 AbstractConfiguration::getUInt64(const std::string& key, UInt64 defaultVa std::string value; if (getRaw(key, value)) - return NumberParser::parseUnsigned64(internalExpand(value)); + return parseUInt64(internalExpand(value)); else return defaultValue; } @@ -462,13 +462,13 @@ std::string AbstractConfiguration::uncheckedExpand(const std::string& value) con int AbstractConfiguration::parseInt(const std::string& value) { if ((value.compare(0, 2, "0x") == 0) || (value.compare(0, 2, "0X") == 0)) - return NumberParser::parseHex(value); + return static_cast(NumberParser::parseHex(value)); else return NumberParser::parse(value); } -int AbstractConfiguration::parseUInt(const std::string& value) +unsigned AbstractConfiguration::parseUInt(const std::string& value) { if ((value.compare(0, 2, "0x") == 0) || (value.compare(0, 2, "0X") == 0)) return NumberParser::parseHex(value); @@ -480,7 +480,7 @@ int AbstractConfiguration::parseUInt(const std::string& value) Int64 AbstractConfiguration::parseInt64(const std::string& value) { if ((value.compare(0, 2, "0x") == 0) || (value.compare(0, 2, "0X") == 0)) - return NumberParser::parseHex64(value); + return static_cast(NumberParser::parseHex64(value)); else return NumberParser::parse64(value); } diff --git a/Util/testsuite/src/AbstractConfigurationTest.cpp b/Util/testsuite/src/AbstractConfigurationTest.cpp index c74ca5c0d..fef002ee1 100644 --- a/Util/testsuite/src/AbstractConfigurationTest.cpp +++ b/Util/testsuite/src/AbstractConfigurationTest.cpp @@ -89,6 +89,7 @@ void AbstractConfigurationTest::testGetInt() assert (pConf->getInt("prop4.int1") == 42); assert (pConf->getInt("prop4.int2") == -42); assert (pConf->getInt("prop4.hex") == 0x1f); + assert (pConf->getUInt("prop4.hex") == 0x1f); assert (pConf->getInt("ref2") == 42); try @@ -114,6 +115,8 @@ void AbstractConfigurationTest::testGetInt64() assert (pConf->getInt64("prop4.bigint1") == std::numeric_limits::max()); assert (pConf->getInt64("prop4.bigint2") == std::numeric_limits::min()); assert (pConf->getUInt64("prop4.biguint") == std::numeric_limits::max()); + assert (pConf->getInt64("prop4.hex") == 0x1f); + assert (pConf->getUInt64("prop4.hex") == 0x1f); assert (pConf->getInt64("ref2") == 42); try