Skip to content

Commit

Permalink
Use std::numeric_limits<UNSIGNED>::max()) instead of (UNSIGNED)-1
Browse files Browse the repository at this point in the history
  • Loading branch information
practicalswift authored and hebasto committed Dec 4, 2018
1 parent 6b82fc5 commit cf4b032
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/arith_uint256.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <assert.h>
#include <cstring>
#include <limits>
#include <stdexcept>
#include <stdint.h>
#include <string>
Expand Down Expand Up @@ -189,7 +190,7 @@ class base_uint
{
// 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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ class CBufferedFile

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;
}
Expand Down Expand Up @@ -846,7 +846,7 @@ class CBufferedFile

// 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;
Expand Down
2 changes: 1 addition & 1 deletion src/test/serialize_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/sighash_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit cf4b032

Please sign in to comment.