Skip to content

Commit 62f3977

Browse files
committed
Merge #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
2 parents 854ca85 + 8931a95 commit 62f3977

File tree

6 files changed

+11
-18
lines changed

6 files changed

+11
-18
lines changed

src/qt/rpcconsole.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <netbase.h>
1919
#include <rpc/server.h>
2020
#include <rpc/client.h>
21+
#include <util/strencodings.h>
2122
#include <util/system.h>
2223

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

src/test/getarg_tests.cpp

Lines changed: 2 additions & 1 deletion
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_bitcoin.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(), "testbitcoin");

src/uint256.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void base_blob<BITS>::SetHex(const char* psz)
3333
psz++;
3434

3535
// skip 0x
36-
if (psz[0] == '0' && tolower(psz[1]) == 'x')
36+
if (psz[0] == '0' && ToLower((unsigned char)psz[1]) == 'x')
3737
psz += 2;
3838

3939
// hex string to uint

src/util/moneystr.cpp

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
443443
key.erase(is_index);
444444
}
445445
#ifdef WIN32
446-
std::transform(key.begin(), key.end(), key.begin(), ::tolower);
446+
std::transform(key.begin(), key.end(), key.begin(), ToLower);
447447
if (key[0] == '/')
448448
key[0] = '-';
449449
#endif

test/lint/lint-locale-dependence.sh

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,21 @@ export LC_ALL=C
44
KNOWN_VIOLATIONS=(
55
"src/bitcoin-tx.cpp.*stoul"
66
"src/bitcoin-tx.cpp.*trim_right"
7-
"src/bitcoin-tx.cpp:.*atoi"
8-
"src/core_read.cpp.*is_digit"
97
"src/dbwrapper.cpp.*stoul"
108
"src/dbwrapper.cpp:.*vsnprintf"
119
"src/httprpc.cpp.*trim"
1210
"src/init.cpp:.*atoi"
1311
"src/qt/rpcconsole.cpp:.*atoi"
14-
"src/qt/rpcconsole.cpp:.*isdigit"
1512
"src/rest.cpp:.*strtol"
1613
"src/test/dbwrapper_tests.cpp:.*snprintf"
17-
"src/test/getarg_tests.cpp.*split"
1814
"src/torcontrol.cpp:.*atoi"
1915
"src/torcontrol.cpp:.*strtol"
20-
"src/uint256.cpp:.*tolower"
21-
"src/util/system.cpp:.*atoi"
22-
"src/util/system.cpp:.*fprintf"
23-
"src/util/system.cpp:.*tolower"
24-
"src/util/moneystr.cpp:.*isdigit"
2516
"src/util/strencodings.cpp:.*atoi"
2617
"src/util/strencodings.cpp:.*strtol"
27-
"src/util/strencodings.cpp:.*strtoll"
2818
"src/util/strencodings.cpp:.*strtoul"
29-
"src/util/strencodings.cpp:.*strtoull"
3019
"src/util/strencodings.h:.*atoi"
20+
"src/util/system.cpp:.*atoi"
21+
"src/util/system.cpp:.*fprintf"
3122
)
3223

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

0 commit comments

Comments
 (0)