Use const in COutPoint class #14838

pull hebasto wants to merge 2 commits into bitcoin:master from hebasto:20181129-const-null-outpoint changing 5 files +11 −8
  1. hebasto commented at 9:13 AM on November 29, 2018: member

    Refactoring:

    • all cases of using (uint32_t) -1 in COutPoint class are replaced with const;
    • also all remaining instances of (UNSIGNED)-1 transformed to std::numeric_limits<UNSIGNED>::max() (by @practicalswift).
  2. fanquake added the label Refactoring on Nov 29, 2018
  3. in src/primitives/transaction.h:24 in 95e2c1a9ac outdated
      20 | @@ -21,7 +21,9 @@ class COutPoint
      21 |      uint256 hash;
      22 |      uint32_t n;
      23 |  
      24 | -    COutPoint(): n((uint32_t) -1) { }
      25 | +    static constexpr uint32_t NULL_OUTPOINT_N = (uint32_t) -1;
    


    practicalswift commented at 9:25 AM on November 29, 2018:

    Use std::numeric_limits<uint32_t>::max() instead :-)

  4. practicalswift commented at 9:25 AM on November 29, 2018: contributor

    Concept ACK modulo review comment

  5. hebasto force-pushed on Nov 29, 2018
  6. hebasto commented at 9:54 AM on November 29, 2018: member

    @practicalswift Thank you for your review. Your comment has been addressed.

  7. practicalswift commented at 10:18 AM on November 29, 2018: contributor

    utACK 6a537172cb96efbbaa6cdd8d31d4938dab4b648d

  8. Empact commented at 12:31 AM on November 30, 2018: member

    nit: Maybe call it NULL_INDEX, as n is short for index, and the value is already scoped to COutPoint.

  9. Use const in COutPoint class 6b82fc59eb
  10. hebasto force-pushed on Nov 30, 2018
  11. hebasto commented at 10:55 AM on November 30, 2018: member

    @Empact Thank you for your review. Your comment has been addressed.

  12. promag commented at 3:16 PM on December 3, 2018: member

    utACK 6b82fc5.

  13. practicalswift commented at 3:36 PM on December 3, 2018: contributor

    utACK 6b82fc59eb19004e54f910261a40d5e1b9e44b42

  14. MarcoFalke commented at 6:03 PM on December 3, 2018: member

    utACK 6b82fc59eb

  15. Empact commented at 11:08 AM on December 4, 2018: member

    utACK 6b82fc5

  16. practicalswift commented at 12:19 PM on December 4, 2018: contributor

    @hebasto Consider cherry-picking in https://github.com/bitcoin/bitcoin/commit/35c6ba8c64de02069bc82dbcc790193f05332f78 which transforms all remaining instances of (UNSIGNED)-1 to std::numeric_limits<UNSIGNED>::max().

  17. hebasto commented at 1:40 PM on December 4, 2018: member

    @practicalswift

    Consider cherry-picking in 35c6ba8 which transforms all remaining instances of (UNSIGNED)-1 to std::numeric_limits<UNSIGNED>::max().

    I don't how to point my local git to 35c6ba8c64de02069bc82dbcc790193f05332f78 commit (cannot see related PR). Would you mind showing me how to do this?

    Btw, what's your nick on IRC (to get in touch)?

  18. practicalswift commented at 2:28 PM on December 4, 2018: contributor

    @hebasto The easiest way to do it is probably:

    curl https://github.com/bitcoin/bitcoin/commit/35c6ba8c64de02069bc82dbcc790193f05332f78.patch \
        | git am
    
  19. Use std::numeric_limits<UNSIGNED>::max()) instead of (UNSIGNED)-1 cf4b0327ed
  20. hebasto commented at 6:26 PM on December 4, 2018: member

    @practicalswift

    Consider cherry-picking in 35c6ba8 which transforms all remaining instances of (UNSIGNED)-1 to std::numeric_limits<UNSIGNED>::max().

    Done.

  21. practicalswift commented at 8:48 PM on December 4, 2018: contributor

    utACK cf4b0327ed92ca8a1533cdf6c2b0015fd9b56397

  22. Empact commented at 11:14 PM on December 4, 2018: member

    I would drop the latter commit. The PR stands alone and has 4 acks as-was. Introducing the latter commit broadens the scope unnecessarily.

    E.g. the latter commit ~is not comprehensive, and~ has no mechanism to ensure ongoing enforcement (compiler warning).

  23. practicalswift commented at 7:52 AM on December 5, 2018: contributor

    @Empact The latter commit is meant to be comprehensive: did you find any counterexample?

  24. Empact commented at 8:39 AM on December 5, 2018: member

    Ironically I found an example that was not addressed by the second commit but had already been by the first, so no I don’t know of one.

  25. promag commented at 9:01 AM on December 5, 2018: member

    utACK cf4b032, no harm in being more comprehensive.

  26. in src/primitives/transaction.h:24 in cf4b0327ed
      20 | @@ -21,7 +21,9 @@ class COutPoint
      21 |      uint256 hash;
      22 |      uint32_t n;
      23 |  
      24 | -    COutPoint(): n((uint32_t) -1) { }
      25 | +    static constexpr uint32_t NULL_INDEX = std::numeric_limits<uint32_t>::max();
    


    Empact commented at 8:47 AM on December 6, 2018:

    Should add #include <limits> to this file

  27. in src/test/serialize_tests.cpp:203 in cf4b0327ed
     199 | @@ -200,7 +200,7 @@ BOOST_AUTO_TEST_CASE(varints)
     200 |      }
     201 |  
     202 |      for (uint64_t i = 0;  i < 100000000000ULL; i += 999999937) {
     203 | -        uint64_t j = -1;
     204 | +        uint64_t j = std::numeric_limits<uint64_t>::max();
    


    Empact commented at 8:47 AM on December 6, 2018:

    Should add #include <limits> to this file

  28. in src/test/sighash_tests.cpp:108 in cf4b0327ed
     104 | @@ -105,7 +105,7 @@ void static RandomTransaction(CMutableTransaction &tx, bool fSingle) {
     105 |          txin.prevout.hash = InsecureRand256();
     106 |          txin.prevout.n = InsecureRandBits(2);
     107 |          RandomScript(txin.scriptSig);
     108 | -        txin.nSequence = (InsecureRandBool()) ? InsecureRand32() : (unsigned int)-1;
     109 | +        txin.nSequence = (InsecureRandBool()) ? InsecureRand32() : std::numeric_limits<uint32_t>::max();
    


    Empact commented at 8:48 AM on December 6, 2018:

    Should add #include <limits> to this file

  29. Empact commented at 8:49 AM on December 6, 2018: member

    Fair enough! Though on second look I noticed some missing includes, as noted.

  30. laanwj commented at 2:37 PM on December 6, 2018: member

    utACK cf4b0327ed92ca8a1533cdf6c2b0015fd9b56397

  31. laanwj merged this on Dec 6, 2018
  32. laanwj closed this on Dec 6, 2018

  33. laanwj referenced this in commit 127b30cce8 on Dec 6, 2018
  34. hebasto deleted the branch on Dec 6, 2018
  35. deadalnix referenced this in commit 4b1e7c0910 on Mar 12, 2020
  36. ftrader referenced this in commit e636e8cf78 on May 19, 2020
  37. PastaPastaPasta referenced this in commit 3b7b3d23cf on Jun 27, 2021
  38. PastaPastaPasta referenced this in commit cadc497d7a on Jun 28, 2021
  39. PastaPastaPasta referenced this in commit 4b3df9e8fd on Jun 29, 2021
  40. PastaPastaPasta referenced this in commit 1bf14e42c8 on Jul 1, 2021
  41. PastaPastaPasta referenced this in commit 3d0903d802 on Jul 1, 2021
  42. PastaPastaPasta referenced this in commit 42acfa76a4 on Jul 1, 2021
  43. UdjinM6 referenced this in commit 90871ec251 on Jul 5, 2021
  44. PastaPastaPasta referenced this in commit b83cab5441 on Jul 8, 2021
  45. gades referenced this in commit 56ec015e1c on Apr 23, 2022
  46. DrahtBot locked this on Aug 16, 2022

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-22 06:15 UTC

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