diff options
-rw-r--r-- | contrib/qos/tc.sh | 2 | ||||
-rw-r--r-- | contrib/verify-commits/trusted-keys | 1 | ||||
-rw-r--r-- | doc/developer-notes.md | 27 | ||||
-rw-r--r-- | src/arith_uint256.h | 3 | ||||
-rw-r--r-- | src/primitives/transaction.h | 8 | ||||
-rwxr-xr-x | src/qt/res/movies/makespinner.sh | 2 | ||||
-rw-r--r-- | src/streams.h | 4 | ||||
-rw-r--r-- | src/test/serialize_tests.cpp | 2 | ||||
-rw-r--r-- | src/test/sighash_tests.cpp | 2 | ||||
-rwxr-xr-x | test/lint/commit-script-check.sh | 18 | ||||
-rwxr-xr-x | test/lint/lint-python-dead-code.sh | 2 | ||||
-rwxr-xr-x | test/lint/lint-shebang.sh (renamed from test/lint/lint-python-shebang.sh) | 9 |
12 files changed, 61 insertions, 19 deletions
diff --git a/contrib/qos/tc.sh b/contrib/qos/tc.sh index 738ea70dbe..5f9b87d9b2 100644 --- a/contrib/qos/tc.sh +++ b/contrib/qos/tc.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash +# # Copyright (c) 2017 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/contrib/verify-commits/trusted-keys b/contrib/verify-commits/trusted-keys index 5610692616..a10da9d822 100644 --- a/contrib/verify-commits/trusted-keys +++ b/contrib/verify-commits/trusted-keys @@ -2,3 +2,4 @@ 133EAC179436F14A5CF1B794860FEB804E669320 32EE5C4C3FA15CCADB46ABE529D4BCB6416F53EC B8B3F1C0E58C15DB6A81D30C3648A882F4316B9B +CA03882CB1FC067B5D3ACFE4D300116E1C875A3D diff --git a/doc/developer-notes.md b/doc/developer-notes.md index 51627dfa8e..a6df17ddd8 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -28,6 +28,8 @@ Developer Notes - [Strings and formatting](#strings-and-formatting) - [Variable names](#variable-names) - [Threads and synchronization](#threads-and-synchronization) + - [Scripts](#scripts) + - [Shebang](#shebang) - [Source code organization](#source-code-organization) - [GUI](#gui) - [Subtrees](#subtrees) @@ -602,6 +604,31 @@ TRY_LOCK(cs_vNodes, lockNodes); } ``` +Scripts +-------------------------- + +### Shebang + +- Use `#!/usr/bin/env bash` instead of obsolete `#!/bin/bash`. + + - [*Rationale*](https://github.com/dylanaraps/pure-bash-bible#shebang): + + `#!/bin/bash` assumes it is always installed to /bin/ which can cause issues; + + `#!/usr/bin/env bash` searches the user's PATH to find the bash binary. + + OK: + +```bash +#!/usr/bin/env bash +``` + + Wrong: + +```bash +#!/bin/bash +``` + Source code organization -------------------------- diff --git a/src/arith_uint256.h b/src/arith_uint256.h index 5cc273be27..bd0360087d 100644 --- a/src/arith_uint256.h +++ b/src/arith_uint256.h @@ -8,6 +8,7 @@ #include <assert.h> #include <cstring> +#include <limits> #include <stdexcept> #include <stdint.h> #include <string> @@ -189,7 +190,7 @@ public: { // prefix operator int i = 0; - while (i < WIDTH && --pn[i] == (uint32_t)-1) + while (i < WIDTH && --pn[i] == std::numeric_limits<uint32_t>::max()) i++; return *this; } diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 0f834eb8c1..c88d5b1ad3 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -21,7 +21,9 @@ public: uint256 hash; uint32_t n; - COutPoint(): n((uint32_t) -1) { } + static constexpr uint32_t NULL_INDEX = std::numeric_limits<uint32_t>::max(); + + COutPoint(): n(NULL_INDEX) { } COutPoint(const uint256& hashIn, uint32_t nIn): hash(hashIn), n(nIn) { } ADD_SERIALIZE_METHODS; @@ -32,8 +34,8 @@ public: READWRITE(n); } - void SetNull() { hash.SetNull(); n = (uint32_t) -1; } - bool IsNull() const { return (hash.IsNull() && n == (uint32_t) -1); } + void SetNull() { hash.SetNull(); n = NULL_INDEX; } + bool IsNull() const { return (hash.IsNull() && n == NULL_INDEX); } friend bool operator<(const COutPoint& a, const COutPoint& b) { diff --git a/src/qt/res/movies/makespinner.sh b/src/qt/res/movies/makespinner.sh index 76e36e4f31..f47c66e02c 100755 --- a/src/qt/res/movies/makespinner.sh +++ b/src/qt/res/movies/makespinner.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash +# # Copyright (c) 2014-2015 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/streams.h b/src/streams.h index dc20f7a9da..d5565fe61f 100644 --- a/src/streams.h +++ b/src/streams.h @@ -761,7 +761,7 @@ protected: public: CBufferedFile(FILE *fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nTypeIn, int nVersionIn) : - nType(nTypeIn), nVersion(nVersionIn), nSrcPos(0), nReadPos(0), nReadLimit((uint64_t)(-1)), nRewind(nRewindIn), vchBuf(nBufSize, 0) + nType(nTypeIn), nVersion(nVersionIn), nSrcPos(0), nReadPos(0), nReadLimit(std::numeric_limits<uint64_t>::max()), nRewind(nRewindIn), vchBuf(nBufSize, 0) { src = fileIn; } @@ -846,7 +846,7 @@ public: // prevent reading beyond a certain position // no argument removes the limit - bool SetLimit(uint64_t nPos = (uint64_t)(-1)) { + bool SetLimit(uint64_t nPos = std::numeric_limits<uint64_t>::max()) { if (nPos < nReadPos) return false; nReadLimit = nPos; diff --git a/src/test/serialize_tests.cpp b/src/test/serialize_tests.cpp index e754996d2f..002f61f6a2 100644 --- a/src/test/serialize_tests.cpp +++ b/src/test/serialize_tests.cpp @@ -200,7 +200,7 @@ BOOST_AUTO_TEST_CASE(varints) } for (uint64_t i = 0; i < 100000000000ULL; i += 999999937) { - uint64_t j = -1; + uint64_t j = std::numeric_limits<uint64_t>::max(); ss >> VARINT(j); BOOST_CHECK_MESSAGE(i == j, "decoded:" << j << " expected:" << i); } diff --git a/src/test/sighash_tests.cpp b/src/test/sighash_tests.cpp index c329844341..773204a00c 100644 --- a/src/test/sighash_tests.cpp +++ b/src/test/sighash_tests.cpp @@ -105,7 +105,7 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle) { txin.prevout.hash = InsecureRand256(); txin.prevout.n = InsecureRandBits(2); RandomScript(txin.scriptSig); - txin.nSequence = (InsecureRandBool()) ? InsecureRand32() : (unsigned int)-1; + txin.nSequence = (InsecureRandBool()) ? InsecureRand32() : std::numeric_limits<uint32_t>::max(); } for (int out = 0; out < outs; out++) { tx.vout.push_back(CTxOut()); diff --git a/test/lint/commit-script-check.sh b/test/lint/commit-script-check.sh index f1327469f3..4267f9fa0d 100755 --- a/test/lint/commit-script-check.sh +++ b/test/lint/commit-script-check.sh @@ -20,23 +20,23 @@ fi RET=0 PREV_BRANCH=`git name-rev --name-only HEAD` PREV_HEAD=`git rev-parse HEAD` -for i in `git rev-list --reverse $1`; do - if git rev-list -n 1 --pretty="%s" $i | grep -q "^scripted-diff:"; then - git checkout --quiet $i^ || exit - SCRIPT="`git rev-list --format=%b -n1 $i | sed '/^-BEGIN VERIFY SCRIPT-$/,/^-END VERIFY SCRIPT-$/{//!b};d'`" +for commit in `git rev-list --reverse $1`; do + if git rev-list -n 1 --pretty="%s" $commit | grep -q "^scripted-diff:"; then + git checkout --quiet $commit^ || exit + SCRIPT="`git rev-list --format=%b -n1 $commit | sed '/^-BEGIN VERIFY SCRIPT-$/,/^-END VERIFY SCRIPT-$/{//!b};d'`" if test "x$SCRIPT" = "x"; then - echo "Error: missing script for: $i" + echo "Error: missing script for: $commit" echo "Failed" RET=1 else - echo "Running script for: $i" + echo "Running script for: $commit" echo "$SCRIPT" - eval "$SCRIPT" - git --no-pager diff --exit-code $i && echo "OK" || (echo "Failed"; false) || RET=1 + (eval "$SCRIPT") + git --no-pager diff --exit-code $commit && echo "OK" || (echo "Failed"; false) || RET=1 fi git reset --quiet --hard HEAD else - if git rev-list "--format=%b" -n1 $i | grep -q '^-\(BEGIN\|END\)[ a-zA-Z]*-$'; then + if git rev-list "--format=%b" -n1 $commit | grep -q '^-\(BEGIN\|END\)[ a-zA-Z]*-$'; then echo "Error: script block marker but no scripted-diff in title" echo "Failed" RET=1 diff --git a/test/lint/lint-python-dead-code.sh b/test/lint/lint-python-dead-code.sh index 3341f794f9..4561b0db30 100755 --- a/test/lint/lint-python-dead-code.sh +++ b/test/lint/lint-python-dead-code.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright (c) 2018 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying diff --git a/test/lint/lint-python-shebang.sh b/test/lint/lint-shebang.sh index 4ff87f0bf7..fda22592d3 100755 --- a/test/lint/lint-python-shebang.sh +++ b/test/lint/lint-shebang.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Shebang must use python3 (not python or python2) +# Assert expected shebang lines export LC_ALL=C EXIT_CODE=0 @@ -10,4 +10,11 @@ for PYTHON_FILE in $(git ls-files -- "*.py"); do EXIT_CODE=1 fi done +for SHELL_FILE in $(git ls-files -- "*.sh"); do + if [[ $(head -n 1 "${SHELL_FILE}") != "#!/usr/bin/env bash" && + $(head -n 1 "${SHELL_FILE}") != "#!/bin/sh" ]]; then + echo "Missing expected shebang \"#!/usr/bin/env bash\" or \"#!/bin/sh\" in ${SHELL_FILE}" + EXIT_CODE=1 + fi +done exit ${EXIT_CODE} |