From e70cc8983c570bbacee37a67df86b1bf959894df Mon Sep 17 00:00:00 2001 From: practicalswift Date: Mon, 29 Oct 2018 09:13:07 +0100 Subject: [PATCH 1/5] Use IsDigit(...) instead of std::isdigit --- src/qt/rpcconsole.cpp | 3 ++- src/util/moneystr.cpp | 6 +++--- test/lint/lint-locale-dependence.sh | 5 ----- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index 606f1d2910e..c8d169a29db 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -226,7 +227,7 @@ bool RPCConsole::RPCParseCommandLine(interfaces::Node* node, std::string &strRes if (lastResult.isArray()) { for(char argch: curarg) - if (!std::isdigit(argch)) + if (!IsDigit(argch)) throw std::runtime_error("Invalid result query"); subelement = lastResult[atoi(curarg.c_str())]; } diff --git a/src/util/moneystr.cpp b/src/util/moneystr.cpp index 4c4de7b7292..f4e41eea4f6 100644 --- a/src/util/moneystr.cpp +++ b/src/util/moneystr.cpp @@ -20,7 +20,7 @@ std::string FormatMoney(const CAmount& n) // Right-trim excess zeros before the decimal point: int nTrim = 0; - for (int i = str.size()-1; (str[i] == '0' && isdigit(str[i-2])); --i) + for (int i = str.size()-1; (str[i] == '0' && IsDigit(str[i-2])); --i) ++nTrim; if (nTrim) str.erase(str.size()-nTrim, nTrim); @@ -49,7 +49,7 @@ bool ParseMoney(const char* pszIn, CAmount& nRet) { p++; int64_t nMult = COIN / 10; - while (isdigit(*p) && (nMult > 0)) + while (IsDigit(*p) && (nMult > 0)) { nUnits += nMult * (*p++ - '0'); nMult /= 10; @@ -58,7 +58,7 @@ bool ParseMoney(const char* pszIn, CAmount& nRet) } if (IsSpace(*p)) break; - if (!isdigit(*p)) + if (!IsDigit(*p)) return false; strWhole.insert(strWhole.end(), *p); } diff --git a/test/lint/lint-locale-dependence.sh b/test/lint/lint-locale-dependence.sh index 44170a6b5ac..59881ce882f 100755 --- a/test/lint/lint-locale-dependence.sh +++ b/test/lint/lint-locale-dependence.sh @@ -5,13 +5,11 @@ KNOWN_VIOLATIONS=( "src/bitcoin-tx.cpp.*stoul" "src/bitcoin-tx.cpp.*trim_right" "src/bitcoin-tx.cpp:.*atoi" - "src/core_read.cpp.*is_digit" "src/dbwrapper.cpp.*stoul" "src/dbwrapper.cpp:.*vsnprintf" "src/httprpc.cpp.*trim" "src/init.cpp:.*atoi" "src/qt/rpcconsole.cpp:.*atoi" - "src/qt/rpcconsole.cpp:.*isdigit" "src/rest.cpp:.*strtol" "src/test/dbwrapper_tests.cpp:.*snprintf" "src/test/getarg_tests.cpp.*split" @@ -21,12 +19,9 @@ KNOWN_VIOLATIONS=( "src/util/system.cpp:.*atoi" "src/util/system.cpp:.*fprintf" "src/util/system.cpp:.*tolower" - "src/util/moneystr.cpp:.*isdigit" "src/util/strencodings.cpp:.*atoi" "src/util/strencodings.cpp:.*strtol" - "src/util/strencodings.cpp:.*strtoll" "src/util/strencodings.cpp:.*strtoul" - "src/util/strencodings.cpp:.*strtoull" "src/util/strencodings.h:.*atoi" ) From c5fd143edb85d0c181e21a429f9e29d12a611831 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Mon, 29 Oct 2018 09:15:11 +0100 Subject: [PATCH 2/5] Use ToLower(...) instead of std::tolower --- src/uint256.cpp | 2 +- src/util/system.cpp | 2 +- test/lint/lint-locale-dependence.sh | 2 -- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/uint256.cpp b/src/uint256.cpp index d9da6680360..b723f9ee544 100644 --- a/src/uint256.cpp +++ b/src/uint256.cpp @@ -33,7 +33,7 @@ void base_blob::SetHex(const char* psz) psz++; // skip 0x - if (psz[0] == '0' && tolower(psz[1]) == 'x') + if (psz[0] == '0' && ToLower((unsigned char)psz[1]) == 'x') psz += 2; // hex string to uint diff --git a/src/util/system.cpp b/src/util/system.cpp index 4f5dd2d6e97..633b616dc39 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -422,7 +422,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin key.erase(is_index); } #ifdef WIN32 - std::transform(key.begin(), key.end(), key.begin(), ::tolower); + std::transform(key.begin(), key.end(), key.begin(), ToLower); if (key[0] == '/') key[0] = '-'; #endif diff --git a/test/lint/lint-locale-dependence.sh b/test/lint/lint-locale-dependence.sh index 59881ce882f..2765ebe5c74 100755 --- a/test/lint/lint-locale-dependence.sh +++ b/test/lint/lint-locale-dependence.sh @@ -15,10 +15,8 @@ KNOWN_VIOLATIONS=( "src/test/getarg_tests.cpp.*split" "src/torcontrol.cpp:.*atoi" "src/torcontrol.cpp:.*strtol" - "src/uint256.cpp:.*tolower" "src/util/system.cpp:.*atoi" "src/util/system.cpp:.*fprintf" - "src/util/system.cpp:.*tolower" "src/util/strencodings.cpp:.*atoi" "src/util/strencodings.cpp:.*strtol" "src/util/strencodings.cpp:.*strtoul" From 587924f0006d2eb9b8218b6abffe181bb9c27513 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Mon, 5 Nov 2018 17:22:09 +0100 Subject: [PATCH 3/5] Use IsSpace(...) instead of boost::is_space --- src/test/getarg_tests.cpp | 2 +- test/lint/lint-locale-dependence.sh | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/test/getarg_tests.cpp b/src/test/getarg_tests.cpp index 0432ede3e00..43e3cea0d93 100644 --- a/src/test/getarg_tests.cpp +++ b/src/test/getarg_tests.cpp @@ -17,7 +17,7 @@ static void ResetArgs(const std::string& strArg) { std::vector vecArg; if (strArg.size()) - boost::split(vecArg, strArg, boost::is_space(), boost::token_compress_on); + boost::split(vecArg, strArg, IsSpace, boost::token_compress_on); // Insert dummy executable name: vecArg.insert(vecArg.begin(), "testbitcoin"); diff --git a/test/lint/lint-locale-dependence.sh b/test/lint/lint-locale-dependence.sh index 2765ebe5c74..c76e862ae23 100755 --- a/test/lint/lint-locale-dependence.sh +++ b/test/lint/lint-locale-dependence.sh @@ -12,15 +12,14 @@ KNOWN_VIOLATIONS=( "src/qt/rpcconsole.cpp:.*atoi" "src/rest.cpp:.*strtol" "src/test/dbwrapper_tests.cpp:.*snprintf" - "src/test/getarg_tests.cpp.*split" "src/torcontrol.cpp:.*atoi" "src/torcontrol.cpp:.*strtol" - "src/util/system.cpp:.*atoi" - "src/util/system.cpp:.*fprintf" "src/util/strencodings.cpp:.*atoi" "src/util/strencodings.cpp:.*strtol" "src/util/strencodings.cpp:.*strtoul" "src/util/strencodings.h:.*atoi" + "src/util/system.cpp:.*atoi" + "src/util/system.cpp:.*fprintf" ) REGEXP_IGNORE_EXTERNAL_DEPENDENCIES="^src/(crypto/ctaes/|leveldb/|secp256k1/|tinyformat.h|univalue/)" From 7c9f7907615ff9c10a56ede5a8e47c91cb20fe3b Mon Sep 17 00:00:00 2001 From: practicalswift Date: Tue, 6 Nov 2018 17:31:24 +0100 Subject: [PATCH 4/5] Update KNOWN_VIOLATIONS: Remove fixed violations --- test/lint/lint-locale-dependence.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/test/lint/lint-locale-dependence.sh b/test/lint/lint-locale-dependence.sh index c76e862ae23..1534d5ef683 100755 --- a/test/lint/lint-locale-dependence.sh +++ b/test/lint/lint-locale-dependence.sh @@ -4,7 +4,6 @@ export LC_ALL=C KNOWN_VIOLATIONS=( "src/bitcoin-tx.cpp.*stoul" "src/bitcoin-tx.cpp.*trim_right" - "src/bitcoin-tx.cpp:.*atoi" "src/dbwrapper.cpp.*stoul" "src/dbwrapper.cpp:.*vsnprintf" "src/httprpc.cpp.*trim" From 8931a95beca2b959c7ee73b154ce8a69acbe8599 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Thu, 6 Dec 2018 12:12:15 +0100 Subject: [PATCH 5/5] Include util/strencodings.h which is required for IsSpace(...) --- src/test/getarg_tests.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/getarg_tests.cpp b/src/test/getarg_tests.cpp index 43e3cea0d93..d3701159bf3 100644 --- a/src/test/getarg_tests.cpp +++ b/src/test/getarg_tests.cpp @@ -2,6 +2,7 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include #include #include