From cae9d1791c3f41829aa5438ee211ec6d7ef52231 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Tue, 20 Dec 2022 21:48:10 +0530 Subject: [PATCH] =?UTF-8?q?merge=20bitcoin#20452:=20Replace=20use=20of=20l?= =?UTF-8?q?ocale=20dependent=20atoi(=E2=80=A6)=20with=20locale-independent?= =?UTF-8?q?=20std::from=5Fchars(=E2=80=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bench/string_cast.cpp | 2 +- src/core_read.cpp | 2 +- src/init.cpp | 3 +- src/qt/rpcconsole.cpp | 2 +- src/rpc/governance.cpp | 3 +- src/rpc/masternode.cpp | 3 +- src/rpc/mining.cpp | 2 +- src/rpc/util.cpp | 1 + src/test/fuzz/locale.cpp | 6 --- src/test/fuzz/parse_numbers.cpp | 4 +- src/test/fuzz/string.cpp | 24 ++++++++++ src/test/specialtx_tests.cpp | 1 + src/test/util_tests.cpp | 71 +++++++++++++++++++++++++++++ src/torcontrol.cpp | 2 +- src/util/moneystr.cpp | 3 +- src/util/strencodings.cpp | 14 ------ src/util/strencodings.h | 30 +++++++++++- src/util/system.cpp | 20 ++++---- src/wallet/wallet.h | 4 +- test/lint/lint-locale-dependence.sh | 15 ++---- 20 files changed, 153 insertions(+), 59 deletions(-) diff --git a/src/bench/string_cast.cpp b/src/bench/string_cast.cpp index 25bba3a84f..ff592b7af4 100644 --- a/src/bench/string_cast.cpp +++ b/src/bench/string_cast.cpp @@ -21,7 +21,7 @@ static void int_atoi(benchmark::Bench& bench) { int value; bench.run([&] { - value = atoi("1"); + value = LocaleIndependentAtoi("1"); }); } diff --git a/src/core_read.cpp b/src/core_read.cpp index c910816b08..32318cff11 100644 --- a/src/core_read.cpp +++ b/src/core_read.cpp @@ -58,7 +58,7 @@ CScript ParseScript(const std::string& s) (w->front() == '-' && w->size() > 1 && std::all_of(w->begin()+1, w->end(), ::IsDigit))) { // Number - int64_t n = atoi64(*w); + int64_t n = LocaleIndependentAtoi(*w); //limit the range of numbers ParseScript accepts in decimal //since numbers outside -0xFFFFFFFF...0xFFFFFFFF are illegal in scripts diff --git a/src/init.cpp b/src/init.cpp index b0a354c2cc..f8f21427ff 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -57,6 +57,7 @@ #include #include #include +#include #include #include #include @@ -878,7 +879,7 @@ static void CleanupBlockRevFiles() // start removing block files. int nContigCounter = 0; for (const std::pair& item : mapBlockFiles) { - if (atoi(item.first) == nContigCounter) { + if (LocaleIndependentAtoi(item.first) == nContigCounter) { nContigCounter++; continue; } diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 01ac18e613..8870964fd1 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -227,7 +227,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes for(char argch: curarg) if (!IsDigit(argch)) throw std::runtime_error("Invalid result query"); - subelement = lastResult[atoi(curarg.c_str())]; + subelement = lastResult[LocaleIndependentAtoi(curarg)]; } else if (lastResult.isObject()) subelement = find_value(lastResult, curarg); diff --git a/src/rpc/governance.cpp b/src/rpc/governance.cpp index c253d2e842..beff39406b 100644 --- a/src/rpc/governance.cpp +++ b/src/rpc/governance.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -950,7 +951,7 @@ static UniValue gobject_getcurrentvotes(const JSONRPCRequest& request) if (!request.params[1].isNull() && !request.params[2].isNull()) { uint256 txid = ParseHashV(request.params[1], "Masternode Collateral hash"); std::string strVout = request.params[2].get_str(); - mnCollateralOutpoint = COutPoint(txid, (uint32_t)atoi(strVout)); + mnCollateralOutpoint = COutPoint(txid, LocaleIndependentAtoi(strVout)); } // FIND OBJECT USER IS LOOKING FOR diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index d99a56010d..a737c629bb 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -322,7 +323,7 @@ static UniValue masternode_winners(const JSONRPCRequest& request) std::string strFilter = ""; if (!request.params[0].isNull()) { - nCount = atoi(request.params[0].get_str()); + nCount = LocaleIndependentAtoi(request.params[0].get_str()); } if (!request.params[1].isNull()) { diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 7961257e9f..e3efa4859e 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -736,7 +736,7 @@ static UniValue getblocktemplate(const JSONRPCRequest& request) std::string lpstr = lpval.get_str(); hashWatchedChain.SetHex(lpstr.substr(0, 64)); - nTransactionsUpdatedLastLP = atoi64(lpstr.substr(64)); + nTransactionsUpdatedLastLP = LocaleIndependentAtoi(lpstr.substr(64)); } else { diff --git a/src/rpc/util.cpp b/src/rpc/util.cpp index ae59748281..11cb3aa5a7 100644 --- a/src/rpc/util.cpp +++ b/src/rpc/util.cpp @@ -10,6 +10,7 @@ #include