Refactoring:
- all cases of using
(uint32_t) -1inCOutPointclass are replaced with const; - also all remaining instances of
(UNSIGNED)-1transformed tostd::numeric_limits<UNSIGNED>::max()(by @practicalswift).
Refactoring:
(uint32_t) -1 in COutPoint class are replaced with const;(UNSIGNED)-1 transformed to std::numeric_limits<UNSIGNED>::max() (by @practicalswift).20 | @@ -21,7 +21,9 @@ class COutPoint 21 | uint256 hash; 22 | uint32_t n; 23 | 24 | - COutPoint(): n((uint32_t) -1) { } 25 | + static constexpr uint32_t NULL_OUTPOINT_N = (uint32_t) -1;
Use std::numeric_limits<uint32_t>::max() instead :-)
Concept ACK modulo review comment
@practicalswift Thank you for your review. Your comment has been addressed.
utACK 6a537172cb96efbbaa6cdd8d31d4938dab4b648d
nit: Maybe call it NULL_INDEX, as n is short for index, and the value is already scoped to COutPoint.
utACK 6b82fc5.
utACK 6b82fc59eb19004e54f910261a40d5e1b9e44b42
utACK 6b82fc59eb
utACK 6b82fc5
@hebasto Consider cherry-picking in https://github.com/bitcoin/bitcoin/commit/35c6ba8c64de02069bc82dbcc790193f05332f78 which transforms all remaining instances of (UNSIGNED)-1 to std::numeric_limits<UNSIGNED>::max().
Consider cherry-picking in 35c6ba8 which transforms all remaining instances of
(UNSIGNED)-1tostd::numeric_limits<UNSIGNED>::max().
I don't how to point my local git to 35c6ba8c64de02069bc82dbcc790193f05332f78 commit (cannot see related PR). Would you mind showing me how to do this?
Btw, what's your nick on IRC (to get in touch)?
@hebasto The easiest way to do it is probably:
curl https://github.com/bitcoin/bitcoin/commit/35c6ba8c64de02069bc82dbcc790193f05332f78.patch \
| git am
Consider cherry-picking in 35c6ba8 which transforms all remaining instances of
(UNSIGNED)-1tostd::numeric_limits<UNSIGNED>::max().
Done.
utACK cf4b0327ed92ca8a1533cdf6c2b0015fd9b56397
I would drop the latter commit. The PR stands alone and has 4 acks as-was. Introducing the latter commit broadens the scope unnecessarily.
E.g. the latter commit ~is not comprehensive, and~ has no mechanism to ensure ongoing enforcement (compiler warning).
@Empact The latter commit is meant to be comprehensive: did you find any counterexample?
Ironically I found an example that was not addressed by the second commit but had already been by the first, so no I don’t know of one.
utACK cf4b032, no harm in being more comprehensive.
20 | @@ -21,7 +21,9 @@ class COutPoint 21 | uint256 hash; 22 | uint32_t n; 23 | 24 | - COutPoint(): n((uint32_t) -1) { } 25 | + static constexpr uint32_t NULL_INDEX = std::numeric_limits<uint32_t>::max();
Should add #include <limits> to this file
199 | @@ -200,7 +200,7 @@ BOOST_AUTO_TEST_CASE(varints) 200 | } 201 | 202 | for (uint64_t i = 0; i < 100000000000ULL; i += 999999937) { 203 | - uint64_t j = -1; 204 | + uint64_t j = std::numeric_limits<uint64_t>::max();
Should add #include <limits> to this file
104 | @@ -105,7 +105,7 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle) { 105 | txin.prevout.hash = InsecureRand256(); 106 | txin.prevout.n = InsecureRandBits(2); 107 | RandomScript(txin.scriptSig); 108 | - txin.nSequence = (InsecureRandBool()) ? InsecureRand32() : (unsigned int)-1; 109 | + txin.nSequence = (InsecureRandBool()) ? InsecureRand32() : std::numeric_limits<uint32_t>::max();
Should add #include <limits> to this file
Fair enough! Though on second look I noticed some missing includes, as noted.
utACK cf4b0327ed92ca8a1533cdf6c2b0015fd9b56397