CastToBool() sign bug? #1638

issue jgarzik opened this issue on July 29, 2012
  1. jgarzik commented at 4:15 PM on July 29, 2012: contributor

    If I understand the MPI format correctly, the bit (0x80) used to indicate a negative value is stored at the beginning of the bytestream, not the end. MPI format is big endian, most-significant bit (MSB) first, and the sign bit precedes all that.

    CastToBool() appears to check for the sign bit at the end of the bytestream, rather than the beginning:

            // Can be negative zero
            if (i == vch.size()-1 && vch[i] == 0x80)
                return false;
    
  2. jgarzik commented at 4:21 PM on July 29, 2012: contributor

    Nevermind. CBigNum::getvch() reverses the string (big -> little endian), so the sign bit would indeed be at the end.

  3. jgarzik closed this on Jul 29, 2012

  4. suprnurd referenced this in commit 7ab175a8e3 on Dec 5, 2017
  5. MarcoFalke locked this on Sep 8, 2021
Contributors

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-20 00:16 UTC

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