util: Fail to parse empty string in ParseMoney
This commit is contained in:
2 files changed
+10
No files matched your search
@@ -1199,6 +1199,12 @@ BOOST_AUTO_TEST_CASE(util_ParseMoney)
|
|||||||
BOOST_CHECK(ParseMoney("0.00000001", ret));
|
BOOST_CHECK(ParseMoney("0.00000001", ret));
|
||||||
BOOST_CHECK_EQUAL(ret, COIN/100000000);
|
BOOST_CHECK_EQUAL(ret, COIN/100000000);
|
||||||
|
|
||||||
|
// Parsing amount that can not be represented in ret should fail
|
||||||
|
BOOST_CHECK(!ParseMoney("0.000000001", ret));
|
||||||
|
|
||||||
|
// Parsing empty string should fail
|
||||||
|
BOOST_CHECK(!ParseMoney("", ret));
|
||||||
|
|
||||||
// Attempted 63 bit overflow should fail
|
// Attempted 63 bit overflow should fail
|
||||||
BOOST_CHECK(!ParseMoney("92233720368.54775808", ret));
|
BOOST_CHECK(!ParseMoney("92233720368.54775808", ret));
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ bool ParseMoney(const std::string& str, CAmount& nRet)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (str.empty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
std::string strWhole;
|
std::string strWhole;
|
||||||
int64_t nUnits = 0;
|
int64_t nUnits = 0;
|
||||||
const char* p = str.c_str();
|
const char* p = str.c_str();
|
||||||
|
|||||||
Reference in new issue
Block a user