Skip to content

Taking the value of the element 0 of a vector when the vector is empty #601

@xanatos

Description

@xanatos

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<unsigned char>& 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions