From 395e03c4461c27256c0319adcbf8f2dff31322f3 Mon Sep 17 00:00:00 2001 From: jamescowens Date: Sat, 2 Apr 2022 17:31:57 -0400 Subject: [PATCH 1/4] Fix improper asserts in rpc code to eliminate linter complaint --- src/rpc/dataacq.cpp | 9 ++++++--- src/rpc/rawtransaction.cpp | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/rpc/dataacq.cpp b/src/rpc/dataacq.cpp index 49737fee27..f3de62ef87 100644 --- a/src/rpc/dataacq.cpp +++ b/src/rpc/dataacq.cpp @@ -149,7 +149,7 @@ UniValue rpc_getblockstats(const UniValue& params, bool fHelp) throw runtime_error("getblockstats: failed to read block"); } - assert(block.vtx.size() > 0); + if (!block.vtx.size()) throw runtime_error("getblockstats: block has zero transactions"); unsigned txcountinblock = 0; @@ -604,9 +604,12 @@ UniValue rpc_getrecentblocks(const UniValue& params, bool fHelp) if( (detail<100 && detail>=20) || (detail>=120) ) { CBlock block; - if(!ReadBlockFromDisk(block, cur->nFile, cur->nBlockPos, Params().GetConsensus())) + if (!ReadBlockFromDisk(block, cur->nFile, cur->nBlockPos, Params().GetConsensus())) { throw runtime_error("failed to read block"); - //assert(block.vtx.size() > 0); + } + + if (!block.vtx.size()) throw runtime_error("getblockstats: block has zero transactions"); + const Claim& claim = block.GetClaim(); if(detail<100) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 6f143251a6..384d924760 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -39,7 +39,10 @@ UniValue MRCToJson(const GRC::MRC& mrc); std::vector> GetTxStakeBoincHashInfo(const CMerkleTx& mtx) { - assert(mtx.IsCoinStake() || mtx.IsCoinBase()); + if (!(mtx.IsCoinStake() || mtx.IsCoinBase())) { + throw runtime_error("GetTxStakeBoincHashInfo: transaction is not a coinstake or coinbase"); + } + std::vector> res; // Fetch BlockIndex for tx block From 162fcb1b35cab1455c5dc772e03bb02c93420535 Mon Sep 17 00:00:00 2001 From: jamescowens Date: Sun, 3 Apr 2022 02:36:24 -0400 Subject: [PATCH 2/4] Fix linter complaint on symbol-check.py Also fix false positive spelling error in the changelog. --- CHANGELOG.md | 2 +- contrib/devtools/symbol-check.py | 10 +++++----- test/lint/lint-spelling.ignore-words.txt | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c22a5c6c9..76de28b2a1 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -208,7 +208,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/). - wallet: simplify nTimeSmart calculation #2144 (@div72) - gui: Refresh checkbox and radio button styles #2170 (@cyrossignol) - build: Bump libevent to 2.1.11 #2172 (@barton2526) - - build: Update native_mac_alias, Remove big sur patch file in qt recipe #2173 (@barton2526) + - build: Update native_mac_alias, Remove Big Sur patch file in qt recipe #2173 (@barton2526) - docs: Misc Grammar #2176 (@barton2526) - build: miniupnpc 2.2.2 #2179 (@barton2526) - rpc: Refresh rainbymagnitude #2163 (@jamescowens) diff --git a/contrib/devtools/symbol-check.py b/contrib/devtools/symbol-check.py index edb9e0efb9..56c4ddcb15 100644 --- a/contrib/devtools/symbol-check.py +++ b/contrib/devtools/symbol-check.py @@ -152,12 +152,12 @@ def read_symbols(executable, imports=True) -> List[Tuple[str, str, str]]: raise IOError('Could not read symbols for {}: {}'.format(executable, stderr.strip())) syms = [] for line in stdout.splitlines(): - line = line.split() + splitline = line.split() if 'Machine:' in line: - arch = line[-1] - if len(line)>7 and re.match('[0-9]+:$', line[0]): - (sym, _, version) = line[7].partition('@') - is_import = line[6] == 'UND' + arch = splitline[-1] + if len(splitline)>7 and re.match('[0-9]+:$', splitline[0]): + (sym, _, version) = splitline[7].partition('@') + is_import = splitline[6] == 'UND' if version.startswith('@'): version = version[1:] if is_import == imports: diff --git a/test/lint/lint-spelling.ignore-words.txt b/test/lint/lint-spelling.ignore-words.txt index ff424c9537..59a13e6583 100644 --- a/test/lint/lint-spelling.ignore-words.txt +++ b/test/lint/lint-spelling.ignore-words.txt @@ -23,3 +23,4 @@ dout nin inout smoe +sur From 61453a88caed5a96f85ee9f3163ee05c03933c94 Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Mon, 23 May 2022 10:18:58 -0400 Subject: [PATCH 3/4] Add .ycm_extra_conf.py exception to lint-python-dead-code.sh --- test/lint/lint-python-dead-code.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/test/lint/lint-python-dead-code.sh b/test/lint/lint-python-dead-code.sh index c3b6ff3c98..edb76b9dc9 100755 --- a/test/lint/lint-python-dead-code.sh +++ b/test/lint/lint-python-dead-code.sh @@ -17,6 +17,7 @@ fi # Any value below 100 introduces the risk of false positives, which would create an unacceptable maintenance burden. if ! vulture \ --min-confidence 100 \ + --exclude "src/crc32c/.ycm_extra_conf.py" \ $(git ls-files -- "*.py"); then echo "Python dead code detection found some issues" exit 1 From 7b34bdfbd7e6dc7bbf69ade7607710f5e0bd4ce7 Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Mon, 23 May 2022 10:20:34 -0400 Subject: [PATCH 4/4] Remove fixed linters from ignore exits --- test/lint/lint-all.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/lint/lint-all.sh b/test/lint/lint-all.sh index 4bd0b743db..86a6ad5f87 100755 --- a/test/lint/lint-all.sh +++ b/test/lint/lint-all.sh @@ -19,10 +19,7 @@ LINTALL=$(basename "${BASH_SOURCE[0]}") EXIT_CODE=0 IGNORE_EXIT=( - "lint-assertions.sh" "lint-circular-dependencies.sh" - "lint-python-dead-code.sh" - "lint-python.sh" ) for f in "${SCRIPTDIR}"/lint-*.sh; do