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

issue xanatos opened this issue on November 1, 2011
  1. xanatos commented at 9:46 AM on November 1, 2011: none

    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

  2. laanwj commented at 10:03 AM on November 1, 2011: member

    MSVC is wrong here, taking the address of an empty vector should be legal. That stack overflow page also gives the workaround: add #define _SECURE_SCL 0, or even better, define it in your build script.

  3. laanwj commented at 6:11 AM on December 23, 2013: member

    Although we accept MSVC compatibility patches, we won't actively ourselves make changes to make MSVC happy. Closing.

  4. laanwj closed this on Dec 23, 2013

  5. ptschip referenced this in commit 37557f6d3e on May 22, 2017
  6. kallewoof referenced this in commit 8c21d415be on Oct 4, 2019
  7. Losangelosgenetics referenced this in commit 7e59299dd7 on Mar 12, 2020
  8. rajarshimaitra referenced this in commit fcdd62e308 on Aug 5, 2021
  9. MarcoFalke locked this on Sep 8, 2021
Contributors
Labels

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-29 03:16 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me