aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorpracticalswift <practicalswift@users.noreply.github.com>2020-03-05 20:20:36 +0000
committerpracticalswift <practicalswift@users.noreply.github.com>2020-03-12 14:15:10 +0000
commit100213c5c29ebd7bd50aa885e54594ae10bf87a4 (patch)
tree46f66244d67fa5d0f0f3435c6135844f233a288f /src/util
parent727857d12d040b467f6956019a1698e15d27ccaa (diff)
downloadbitcoin-100213c5c29ebd7bd50aa885e54594ae10bf87a4.tar.xz
util: Fail to parse space-only strings in ParseMoney(...) (instead of parsing as zero)
Diffstat (limited to 'src/util')
-rw-r--r--src/util/moneystr.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/util/moneystr.cpp b/src/util/moneystr.cpp
index 40d8918dfc..544cfb58f9 100644
--- a/src/util/moneystr.cpp
+++ b/src/util/moneystr.cpp
@@ -31,12 +31,12 @@ std::string FormatMoney(const CAmount& n)
}
-bool ParseMoney(const std::string& str, CAmount& nRet)
+bool ParseMoney(const std::string& money_string, CAmount& nRet)
{
- if (!ValidAsCString(str)) {
+ if (!ValidAsCString(money_string)) {
return false;
}
-
+ const std::string str = TrimString(money_string);
if (str.empty()) {
return false;
}
@@ -44,8 +44,6 @@ bool ParseMoney(const std::string& str, CAmount& nRet)
std::string strWhole;
int64_t nUnits = 0;
const char* p = str.c_str();
- while (IsSpace(*p))
- p++;
for (; *p; p++)
{
if (*p == '.')
@@ -60,14 +58,14 @@ bool ParseMoney(const std::string& str, CAmount& nRet)
break;
}
if (IsSpace(*p))
- break;
+ return false;
if (!IsDigit(*p))
return false;
strWhole.insert(strWhole.end(), *p);
}
- for (; *p; p++)
- if (!IsSpace(*p))
- return false;
+ if (*p) {
+ return false;
+ }
if (strWhole.size() > 10) // guard against 63 bit overflow
return false;
if (nUnits < 0 || nUnits > COIN)