Skip to content

Commit

Permalink
Replace uint256(1) with static constant
Browse files Browse the repository at this point in the history
SignatureHash and its test function SignatureHashOld
return uint256(1) as a special error signaling value.
Return a local static constant with the same value instead.
  • Loading branch information
laanwj committed Jan 5, 2015
1 parent 8076585 commit 2eae315
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/script/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1030,16 +1030,17 @@ class CTransactionSignatureSerializer {

uint256 SignatureHash(const CScript& scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType)
{
static const uint256 one("0000000000000000000000000000000000000000000000000000000000000001");
if (nIn >= txTo.vin.size()) {
// nIn out of range
return 1;
return one;
}

// Check for invalid use of SIGHASH_SINGLE
if ((nHashType & 0x1f) == SIGHASH_SINGLE) {
if (nIn >= txTo.vout.size()) {
// nOut out of range
return 1;
return one;
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/test/sighash_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ extern Array read_json(const std::string& jsondata);
// Old script.cpp SignatureHash function
uint256 static SignatureHashOld(CScript scriptCode, const CTransaction& txTo, unsigned int nIn, int nHashType)
{
static const uint256 one("0000000000000000000000000000000000000000000000000000000000000001");
if (nIn >= txTo.vin.size())
{
printf("ERROR: SignatureHash() : nIn=%d out of range\n", nIn);
return 1;
return one;
}
CMutableTransaction txTmp(txTo);

Expand Down Expand Up @@ -58,7 +59,7 @@ uint256 static SignatureHashOld(CScript scriptCode, const CTransaction& txTo, un
if (nOut >= txTmp.vout.size())
{
printf("ERROR: SignatureHash() : nOut=%d out of range\n", nOut);
return 1;
return one;
}
txTmp.vout.resize(nOut+1);
for (unsigned int i = 0; i < nOut; i++)
Expand Down

0 comments on commit 2eae315

Please sign in to comment.