base_uint::operator&=(uint64 b) #616

issue xanatos opened this issue on November 8, 2011
  1. xanatos commented at 2:32 PM on November 8, 2011: none

    uint256.h

    base_uint& operator&=(uint64 b)
    {
        pn[0] &= (unsigned int)b;
        pn[1] &= (unsigned int)(b >> 32);
        return *this;
    }
    

    I think this code is conceptually wrong if connected to the operator &=. It's good enough to be put in a separate function. The problem is that it's doing the "logical and" only on the first two uint. The other uint should be zeroed. For example the base_uint::operator==(const base_uint& a, uint64 b) do checks the other uint of the base_uint for 0. This problem isn't present with the ^= and the |= operators because anything ^ 0 = anything, and anything | 0 = anything.

  2. tcatm commented at 2:48 PM on November 8, 2011: none

    I agree. The behaviour seems wrong.

    Would fixing this break anything (i.e. it is used somewhere)? If not, you could make a pull request to fix it.

  3. laanwj commented at 2:58 PM on November 8, 2011: member

    Yes, conceptually you are right. Anding with a 64 bit number will make it a 64-bit number and discard the rest.

    However, are you very sure nothing relies on the current behavior?

    (If not, I wonder why it is this way. Is it called in a fast/critical loop, making the overhead of zeroing significant?)

  4. gavinandresen commented at 3:14 PM on November 8, 2011: contributor

    Looks like a bug to me. Perfect candidate for a unit test. Looks to me like this method (and all the rest of the bignum &= methods) is not used anywhere in the source.

  5. laanwj commented at 5:20 PM on November 9, 2011: member

    If it is not used, wouldn't it be a good idea to remove it? (it's in git should we need it later...)

  6. sipa referenced this in commit 46245b4782 on Feb 19, 2012
  7. sipa commented at 6:14 PM on February 19, 2012: member

    It's not used indeed; #870 deletes it.

  8. gavinandresen closed this on Feb 27, 2012

  9. sje397 referenced this in commit d731344c0b on Feb 28, 2012
  10. coblee referenced this in commit f87fb36718 on Jul 17, 2012
  11. ptschip referenced this in commit 9198f46315 on Jun 5, 2017
  12. kallewoof referenced this in commit 427903dd97 on Oct 4, 2019
  13. MarcoFalke locked this on Sep 8, 2021

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