Skip to content

Commit cf4b032

Browse files
practicalswifthebasto
authored andcommitted
Use std::numeric_limits<UNSIGNED>::max()) instead of (UNSIGNED)-1
1 parent 6b82fc5 commit cf4b032

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

src/arith_uint256.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <assert.h>
1010
#include <cstring>
11+
#include <limits>
1112
#include <stdexcept>
1213
#include <stdint.h>
1314
#include <string>
@@ -189,7 +190,7 @@ class base_uint
189190
{
190191
// prefix operator
191192
int i = 0;
192-
while (i < WIDTH && --pn[i] == (uint32_t)-1)
193+
while (i < WIDTH && --pn[i] == std::numeric_limits<uint32_t>::max())
193194
i++;
194195
return *this;
195196
}

src/streams.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ class CBufferedFile
761761

762762
public:
763763
CBufferedFile(FILE *fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nTypeIn, int nVersionIn) :
764-
nType(nTypeIn), nVersion(nVersionIn), nSrcPos(0), nReadPos(0), nReadLimit((uint64_t)(-1)), nRewind(nRewindIn), vchBuf(nBufSize, 0)
764+
nType(nTypeIn), nVersion(nVersionIn), nSrcPos(0), nReadPos(0), nReadLimit(std::numeric_limits<uint64_t>::max()), nRewind(nRewindIn), vchBuf(nBufSize, 0)
765765
{
766766
src = fileIn;
767767
}
@@ -846,7 +846,7 @@ class CBufferedFile
846846

847847
// prevent reading beyond a certain position
848848
// no argument removes the limit
849-
bool SetLimit(uint64_t nPos = (uint64_t)(-1)) {
849+
bool SetLimit(uint64_t nPos = std::numeric_limits<uint64_t>::max()) {
850850
if (nPos < nReadPos)
851851
return false;
852852
nReadLimit = nPos;

src/test/serialize_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ BOOST_AUTO_TEST_CASE(varints)
200200
}
201201

202202
for (uint64_t i = 0; i < 100000000000ULL; i += 999999937) {
203-
uint64_t j = -1;
203+
uint64_t j = std::numeric_limits<uint64_t>::max();
204204
ss >> VARINT(j);
205205
BOOST_CHECK_MESSAGE(i == j, "decoded:" << j << " expected:" << i);
206206
}

src/test/sighash_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle) {
105105
txin.prevout.hash = InsecureRand256();
106106
txin.prevout.n = InsecureRandBits(2);
107107
RandomScript(txin.scriptSig);
108-
txin.nSequence = (InsecureRandBool()) ? InsecureRand32() : (unsigned int)-1;
108+
txin.nSequence = (InsecureRandBool()) ? InsecureRand32() : std::numeric_limits<uint32_t>::max();
109109
}
110110
for (int out = 0; out < outs; out++) {
111111
tx.vout.push_back(CTxOut());

0 commit comments

Comments
 (0)