script: Fix reference into empty vector run time exception

Edit by laanwj: `begin_ptr(sourcedata) + sourcedata.size()` -> `end_ptr(sourcedata)`
This commit is contained in:
ENikS 2014-09-23 13:30:27 -04:00 committed by Wladimir J. van der Laan
parent 35ee2dac67
commit 219372f1dd
No known key found for this signature in database
GPG key ID: 74810B012346C9A6
2 changed files with 7 additions and 7 deletions

View file

@ -637,15 +637,15 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
valtype& vch = stacktop(-1); valtype& vch = stacktop(-1);
valtype vchHash((opcode == OP_RIPEMD160 || opcode == OP_SHA1 || opcode == OP_HASH160) ? 20 : 32); valtype vchHash((opcode == OP_RIPEMD160 || opcode == OP_SHA1 || opcode == OP_HASH160) ? 20 : 32);
if (opcode == OP_RIPEMD160) if (opcode == OP_RIPEMD160)
CRIPEMD160().Write(&vch[0], vch.size()).Finalize(&vchHash[0]); CRIPEMD160().Write(begin_ptr(vch), vch.size()).Finalize(begin_ptr(vchHash));
else if (opcode == OP_SHA1) else if (opcode == OP_SHA1)
CSHA1().Write(&vch[0], vch.size()).Finalize(&vchHash[0]); CSHA1().Write(begin_ptr(vch), vch.size()).Finalize(begin_ptr(vchHash));
else if (opcode == OP_SHA256) else if (opcode == OP_SHA256)
CSHA256().Write(&vch[0], vch.size()).Finalize(&vchHash[0]); CSHA256().Write(begin_ptr(vch), vch.size()).Finalize(begin_ptr(vchHash));
else if (opcode == OP_HASH160) else if (opcode == OP_HASH160)
CHash160().Write(&vch[0], vch.size()).Finalize(&vchHash[0]); CHash160().Write(begin_ptr(vch), vch.size()).Finalize(begin_ptr(vchHash));
else if (opcode == OP_HASH256) else if (opcode == OP_HASH256)
CHash256().Write(&vch[0], vch.size()).Finalize(&vchHash[0]); CHash256().Write(begin_ptr(vch), vch.size()).Finalize(begin_ptr(vchHash));
popstack(stack); popstack(stack);
stack.push_back(vchHash); stack.push_back(vchHash);
} }

View file

@ -40,7 +40,7 @@ BOOST_AUTO_TEST_CASE(base58_EncodeBase58)
std::vector<unsigned char> sourcedata = ParseHex(test[0].get_str()); std::vector<unsigned char> sourcedata = ParseHex(test[0].get_str());
std::string base58string = test[1].get_str(); std::string base58string = test[1].get_str();
BOOST_CHECK_MESSAGE( BOOST_CHECK_MESSAGE(
EncodeBase58(&sourcedata[0], &sourcedata[sourcedata.size()]) == base58string, EncodeBase58(begin_ptr(sourcedata), end_ptr(sourcedata)) == base58string,
strTest); strTest);
} }
} }