bitcoin/bitcoin — Issue #601: Taking the value of the element 0 of a vector when the vector is empty
Author: xanatos
Created: 2011-11-01 09:46:42+00:00
State: open

I have compiled bitcoin 0.4 under Visual Studio 2010. I know this isn't supported, but the bug isn't connected to Visual Studio.

In util.h there is this block of code:

inline uint160 Hash160(const std::vector& vch)
{
uint256 hash1;
SHA256(&vch[0], vch.size(), (unsigned char*)&hash1);
uint160 hash2;
RIPEMD160((unsigned char*)&hash1, sizeof(hash1), (unsigned char*)&hash2);
return hash2;
}

Now the problem is that if there isn't a wallet the function is called with an empty vch. In "debug" mode the &vch[0] asserts, because 0 is >= the size of the vector. Read for example http://stackoverflow.com/questions/2728255/c-getting-the-address-of-the-start-of-an-stdvector