mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-03 09:56:38 -05:00
Merge #18225: util: Fail to parse empty string in ParseMoney
8888461f68
util: Fail to parse empty string in ParseMoney (MarcoFalke)fab30b61eb
util: Remove unused ParseMoney that takes a c_str (MarcoFalke) Pull request description: Supplying a fee rate or an amount on the command line as an empty string, which currently parses as `0` seems fragile and confusing. See for example the confusion in #18214. Fixes #18214 ACKs for top commit: Empact: Code Review ACK8888461f68
achow101: ACK8888461f68
instagibbs: utACK8888461f68
Tree-SHA512: ac2d6b7fa89fe5809c34d5f49831042032591c34fb3c76908d72fed51e8bced41bf2b41dc1b3be34ee691a40463355649857a7a8f378709d38ae89503feb11c2
This commit is contained in:
commit
9027960932
3 changed files with 12 additions and 6 deletions
|
@ -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));
|
||||||
|
|
||||||
|
|
|
@ -36,14 +36,14 @@ bool ParseMoney(const std::string& str, CAmount& nRet)
|
||||||
if (!ValidAsCString(str)) {
|
if (!ValidAsCString(str)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return ParseMoney(str.c_str(), nRet);
|
|
||||||
|
if (str.empty()) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ParseMoney(const char* pszIn, CAmount& nRet)
|
|
||||||
{
|
|
||||||
std::string strWhole;
|
std::string strWhole;
|
||||||
int64_t nUnits = 0;
|
int64_t nUnits = 0;
|
||||||
const char* p = pszIn;
|
const char* p = str.c_str();
|
||||||
while (IsSpace(*p))
|
while (IsSpace(*p))
|
||||||
p++;
|
p++;
|
||||||
for (; *p; p++)
|
for (; *p; p++)
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
* JSON but use AmountFromValue and ValueFromAmount for that.
|
* JSON but use AmountFromValue and ValueFromAmount for that.
|
||||||
*/
|
*/
|
||||||
std::string FormatMoney(const CAmount& n);
|
std::string FormatMoney(const CAmount& n);
|
||||||
|
/** Parse an amount denoted in full coins. E.g. "0.0034" supplied on the command line. **/
|
||||||
NODISCARD bool ParseMoney(const std::string& str, CAmount& nRet);
|
NODISCARD bool ParseMoney(const std::string& str, CAmount& nRet);
|
||||||
NODISCARD bool ParseMoney(const char* pszIn, CAmount& nRet);
|
|
||||||
|
|
||||||
#endif // BITCOIN_UTIL_MONEYSTR_H
|
#endif // BITCOIN_UTIL_MONEYSTR_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue