Skip to content

Commit 7a656e1

Browse files
laanwjvijaydasmp
authored andcommitted
Merge bitcoin#14599: Use functions guaranteed to be locale independent (IsDigit, ToLower) in {Format,Parse}Money(...), uint256::SetHex(...), etc. Remove the use of locale dependent boost::is_space(...)
8931a95 Include util/strencodings.h which is required for IsSpace(...) (practicalswift) 7c9f790 Update KNOWN_VIOLATIONS: Remove fixed violations (practicalswift) 587924f Use IsSpace(...) instead of boost::is_space (practicalswift) c5fd143 Use ToLower(...) instead of std::tolower (practicalswift) e70cc89 Use IsDigit(...) instead of std::isdigit (practicalswift) Pull request description: * Use `ToLower(...)` instead of `std::tolower`. `std::tolower` is locale dependent. * Use `IsDigit(...)` instead of `std::isdigit`. Some implementations (e.g. Microsoft in 1252 codepage) may classify single-byte characters other than `[0-9]` as digits. * Update `KNOWN_VIOLATIONS`: Remove fixed violations. * ~~Replace use of locale dependent Boost trim (`boost::trim`) with locale independent `TrimString`.~~ * Use` IsSpace(...)` instead of `boost::is_space` Tree-SHA512: defed016136b530b723fa185afdbd00410925a748856ba3afa4cee60f61a67617e30f304f2b9991a67b5fe075d9624f051e14342aee176f45fbc024d59e1aa82
1 parent 0e5b64c commit 7a656e1

File tree

6 files changed

+11
-18
lines changed

6 files changed

+11
-18
lines changed

src/qt/rpcconsole.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <netbase.h>
2121
#include <rpc/server.h>
2222
#include <rpc/client.h>
23+
#include <util/strencodings.h>
2324
#include <util/system.h>
2425

2526
#include <openssl/crypto.h>
@@ -229,7 +230,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes
229230
if (lastResult.isArray())
230231
{
231232
for(char argch: curarg)
232-
if (!std::isdigit(argch))
233+
if (!IsDigit(argch))
233234
throw std::runtime_error("Invalid result query");
234235
subelement = lastResult[atoi(curarg.c_str())];
235236
}

src/test/getarg_tests.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include <util/strencodings.h>
56
#include <util/system.h>
67
#include <test/test_dash.h>
78

@@ -17,7 +18,7 @@ static void ResetArgs(const std::string& strArg)
1718
{
1819
std::vector<std::string> vecArg;
1920
if (strArg.size())
20-
boost::split(vecArg, strArg, boost::is_space(), boost::token_compress_on);
21+
boost::split(vecArg, strArg, IsSpace, boost::token_compress_on);
2122

2223
// Insert dummy executable name:
2324
vecArg.insert(vecArg.begin(), "testdash");

src/uint256.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void base_blob<BITS>::SetHex(const char* psz)
3737
psz++;
3838

3939
// skip 0x
40-
if (psz[0] == '0' && tolower(psz[1]) == 'x')
40+
if (psz[0] == '0' && ToLower((unsigned char)psz[1]) == 'x')
4141
psz += 2;
4242

4343
// hex string to uint

src/util/moneystr.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ std::string FormatMoney(const CAmount& n)
2020

2121
// Right-trim excess zeros before the decimal point:
2222
int nTrim = 0;
23-
for (int i = str.size()-1; (str[i] == '0' && isdigit(str[i-2])); --i)
23+
for (int i = str.size()-1; (str[i] == '0' && IsDigit(str[i-2])); --i)
2424
++nTrim;
2525
if (nTrim)
2626
str.erase(str.size()-nTrim, nTrim);
@@ -49,7 +49,7 @@ bool ParseMoney(const char* pszIn, CAmount& nRet)
4949
{
5050
p++;
5151
int64_t nMult = COIN / 10;
52-
while (isdigit(*p) && (nMult > 0))
52+
while (IsDigit(*p) && (nMult > 0))
5353
{
5454
nUnits += nMult * (*p++ - '0');
5555
nMult /= 10;
@@ -58,7 +58,7 @@ bool ParseMoney(const char* pszIn, CAmount& nRet)
5858
}
5959
if (IsSpace(*p))
6060
break;
61-
if (!isdigit(*p))
61+
if (!IsDigit(*p))
6262
return false;
6363
strWhole.insert(strWhole.end(), *p);
6464
}

src/util/system.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
482482
key.erase(is_index);
483483
}
484484
#ifdef WIN32
485-
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
485+
std::transform(key.begin(), key.end(), key.begin(), ToLower);
486486
if (key[0] == '/')
487487
key[0] = '-';
488488
#endif

test/lint/lint-locale-dependence.sh

+2-11
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ KNOWN_VIOLATIONS=(
66
"src/bench/string_cast.cpp.*atoi"
77
"src/dash-tx.cpp.*stoul"
88
"src/dash-tx.cpp.*trim_right"
9-
"src/dash-tx.cpp:.*atoi"
10-
"src/core_read.cpp.*is_digit"
119
"src/dbwrapper.cpp.*stoul"
1210
"src/dbwrapper.cpp:.*vsnprintf"
1311
"src/governance/governance-validators.cpp.*isspace"
@@ -16,7 +14,6 @@ KNOWN_VIOLATIONS=(
1614
"src/init.cpp:.*atoi"
1715
"src/init.cpp:.*fprintf"
1816
"src/qt/rpcconsole.cpp:.*atoi"
19-
"src/qt/rpcconsole.cpp:.*isdigit"
2017
"src/rest.cpp:.*strtol"
2118
"src/rpc/blockchain.cpp.*atoi"
2219
"src/rpc/governance.cpp.*atoi"
@@ -25,20 +22,14 @@ KNOWN_VIOLATIONS=(
2522
"src/rpc/server.cpp.*tolower"
2623
"src/statsd_client.cpp:.*snprintf"
2724
"src/test/dbwrapper_tests.cpp:.*snprintf"
28-
"src/test/getarg_tests.cpp.*split"
2925
"src/torcontrol.cpp:.*atoi"
3026
"src/torcontrol.cpp:.*strtol"
31-
"src/uint256.cpp:.*tolower"
32-
"src/util/system.cpp:.*atoi"
33-
"src/util/system.cpp:.*tolower"
34-
"src/util/moneystr.cpp:.*isdigit"
3527
"src/util/strencodings.cpp:.*atoi"
3628
"src/util/strencodings.cpp:.*strtol"
37-
"src/util/strencodings.cpp:.*strtoll"
38-
"src/util/strencodings.cpp:.*strtoul"
39-
"src/util/strencodings.cpp:.*strtoull"
4029
"src/util/strencodings.h:.*atoi"
4130
"src/wallet/wallet.cpp:.*atoi"
31+
"src/util/system.cpp:.*atoi"
32+
"src/util/system.cpp:.*fprintf"
4233
)
4334

4435
REGEXP_IGNORE_EXTERNAL_DEPENDENCIES="^src/(crypto/ctaes/|leveldb/|secp256k1/|tinyformat.h|univalue/)"

0 commit comments

Comments
 (0)