refactor: use braced init for integer literals instead of c style casts #23829

pull PastaPastaPasta wants to merge 1 commits into bitcoin:master from PastaPastaPasta:use-braced-init changing 23 files +47 −47
  1. PastaPastaPasta commented at 6:02 PM on December 20, 2021: contributor

    See #23810 for more context. This is broken out from that PR, as it is less breaking, and should be trivial to review and merge.

    EDIT: Long term, the intention is to remove all C-style casts, as they can dangerously introduce reinterpret_casts. This is one step which removes a number of trivially removable C-style casts

  2. DrahtBot added the label Consensus on Dec 20, 2021
  3. DrahtBot added the label P2P on Dec 20, 2021
  4. DrahtBot added the label Refactoring on Dec 20, 2021
  5. DrahtBot added the label Utils/log/libs on Dec 20, 2021
  6. DrahtBot added the label Validation on Dec 20, 2021
  7. DrahtBot added the label Wallet on Dec 20, 2021
  8. DrahtBot commented at 3:04 AM on December 21, 2021: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK aureleoules
    Concept ACK MarcoFalke
    Stale ACK shaavan

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    No conflicts as of last run.

  9. DrahtBot cross-referenced this on Dec 21, 2021 from issue refactor: Use spans of std::byte in serialize by maflcko
  10. DrahtBot cross-referenced this on Dec 21, 2021 from issue wallet: Derive inactive HD chains in additional places by achow101
  11. maflcko removed the label Wallet on Dec 21, 2021
  12. maflcko removed the label P2P on Dec 21, 2021
  13. maflcko removed the label Validation on Dec 21, 2021
  14. maflcko removed the label Consensus on Dec 21, 2021
  15. maflcko removed the label Utils/log/libs on Dec 21, 2021
  16. maflcko commented at 9:23 AM on December 21, 2021: member

    Concept ACK. I think this is fine to do because:

    • C++11 braced init is safer, since it has more compile time checks
    • This patch has no conflicts as of now
    • bitcoind is not changed by this patch. I checked clang++ -O2 and g++ -O2 on my system.

    Instead of linking to a pull request for context, I think OP can be improved to give a clear motivation. I think this patch is by itself worthwhile and should be considered independent of the other pull request.

    review ACK 9db89e1efa4332109eb1cb53e153844797a60350

    However, I can also see a point about not changing existing code for style reasons, unless it is touched.

  17. shaavan approved
  18. shaavan commented at 10:18 AM on December 21, 2021: contributor

    ACK 9db89e1efa4332109eb1cb53e153844797a60350

    I agree with the reason given by @MarcoFalke in the above comment.

    1. C++11 braced init is safer since it has more compile-time checks
    2. This patch has no conflicts as of now

    I have reviewed the code, and I think all the appropriate changes are correctly made in this PR.

    However, I can also see a point about not changing existing code for style reasons unless it is touched.

    It makes sense. But these style changes will need to be done sooner or later. And since there are not many conflicts (as of now) for this PR, I think these changes can be safely integrated into the codebase.

  19. maflcko commented at 1:16 PM on December 21, 2021: member

    I took another look here and it seems the changes are incomplete. For example, there are a lot of occurrences in the RPC layer:

            ret.pushKV("height", (int64_t)stats.nHeight);
            ret.pushKV("bestblock", stats.hashBlock.GetHex());
            ret.pushKV("txouts", (int64_t)stats.nTransactionOutputs);
            ret.pushKV("bogosize", (int64_t)stats.nBogoSize);
    

    If the changes are made complete here, it will probably be a change too large and not worth it, so I'll downgrade my ACK to a -0.

  20. PastaPastaPasta renamed this:
    refactor: use braced init for integer constants instead of c style casts
    refactor: use braced init for integer literals instead of c style casts
    on Dec 21, 2021
  21. PastaPastaPasta commented at 4:24 PM on December 21, 2021: contributor

    I took another look here and it seems the changes are incomplete. For example, there are a lot of occurrences in the RPC layer:

            ret.pushKV("height", (int64_t)stats.nHeight);
            ret.pushKV("bestblock", stats.hashBlock.GetHex());
            ret.pushKV("txouts", (int64_t)stats.nTransactionOutputs);
            ret.pushKV("bogosize", (int64_t)stats.nBogoSize);
    

    If the changes are made complete here, it will probably be a change too large and not worth it, so I'll downgrade my ACK to a -0. @MarcoFalke the purpose of this PR is to not be complete :D If it was complete, it would simply be #23810.

    The scope of this PR as I understand it (although original title was misleading), was to only apply this to integer literals (I originally said "integer constants").

    I could expand the scope to all integer constants, but that would potentially be too breaking (according to what you've said). Let's maybe do that in the future.

  22. PastaPastaPasta commented at 6:46 PM on December 28, 2021: contributor

    @MarcoFalke Did my scope clarification (PR only intended to touch integer literals) clarify your concerns? It seems to me this PR only would cause conflicts in two other PRs, so there being lot's of conflicts isn't a concern, and it shouldn't change the binary.

  23. PastaPastaPasta commented at 2:35 AM on January 10, 2022: contributor

    @MarcoFalke if possible, I'd like to continue moving forward with this. Did you have any concerns I haven't addressed?

  24. DrahtBot cross-referenced this on Jan 11, 2022 from issue Add defaults to vDeployments to avoid uninitialized variables by ajtowns
  25. DrahtBot added the label Needs rebase on Jan 27, 2022
  26. PastaPastaPasta force-pushed on Jan 28, 2022
  27. PastaPastaPasta commented at 4:57 AM on January 28, 2022: contributor

    I have rebased this PR now that #23438 has been merged. @ajtowns @achow101, this PR will cause a few minor and easily resolvable conflicts in your PR (#24032, #23304). Do either of you have an objection to this PR being merged, and hence requiring a rebase in your PRs?

  28. ajtowns commented at 6:23 AM on January 28, 2022: contributor

    24032 will need a rebase after #23508 is merged anyway

  29. DrahtBot removed the label Needs rebase on Jan 28, 2022
  30. DrahtBot added the label Needs rebase on Mar 2, 2022
  31. PastaPastaPasta force-pushed on Mar 7, 2022
  32. DrahtBot removed the label Needs rebase on Mar 7, 2022
  33. DrahtBot cross-referenced this on Mar 29, 2022 from issue refactor address relay time by maflcko
  34. DrahtBot cross-referenced this on Mar 29, 2022 from issue addrman: Use system time instead of adjusted network time by maflcko
  35. DrahtBot cross-referenced this on Mar 31, 2022 from issue wallet: reduce coin selection iterations by murchandamus
  36. DrahtBot cross-referenced this on Apr 14, 2022 from issue wallet: return error msg for "too-long-mempool-chain" by furszy
  37. DrahtBot cross-referenced this on Apr 24, 2022 from issue wallet: avoid mixing different `OutputTypes` during coin selection by josibake
  38. DrahtBot added the label Needs rebase on May 12, 2022
  39. PastaPastaPasta force-pushed on May 13, 2022
  40. DrahtBot removed the label Needs rebase on May 13, 2022
  41. DrahtBot cross-referenced this on Jun 8, 2022 from issue refactor: Remove redundant addrman time checks by maflcko
  42. DrahtBot added the label Needs rebase on Jun 9, 2022
  43. PastaPastaPasta force-pushed on Jun 9, 2022
  44. DrahtBot removed the label Needs rebase on Jun 9, 2022
  45. DrahtBot cross-referenced this on Jul 1, 2022 from issue [kernel 3c/n] Decouple validation cache initialization from `ArgsManager` by dongcarl
  46. DrahtBot cross-referenced this on Jul 18, 2022 from issue rpc: Filter inputs by type during CoinSelection by aureleoules
  47. DrahtBot added the label Needs rebase on Jul 27, 2022
  48. glozow commented at 10:01 AM on September 26, 2022: member

    @PastaPastaPasta are you still working on this?

  49. PastaPastaPasta commented at 10:02 AM on September 26, 2022: contributor

    I'd love for it to get merged. And would be happy to rebase it. But it seems like most maintainers here don't actually want to review / merge it sadly.

  50. PastaPastaPasta force-pushed on Sep 29, 2022
  51. PastaPastaPasta commented at 7:38 PM on September 29, 2022: contributor

    Rebased :) Hopefully we can get a few reviews on this simple PR. I have liked seeing in my continued rebases as we are refactoring places where ints were previously used and are now using dedicated types that actually mean something.

  52. DrahtBot removed the label Needs rebase on Sep 29, 2022
  53. DrahtBot cross-referenced this on Oct 28, 2022 from issue wallet: group outputs only once, decouple it from Coin Selection by furszy
  54. DrahtBot cross-referenced this on Dec 8, 2022 from issue wallet: Coin Selection, return accurate error messages by furszy
  55. DrahtBot added the label Needs rebase on Jan 4, 2023
  56. refactor: use braced init for integer constants instead of c style casts f2fc03ec85
  57. PastaPastaPasta force-pushed on Jan 4, 2023
  58. DrahtBot removed the label Needs rebase on Jan 4, 2023
  59. aureleoules approved
  60. aureleoules commented at 10:22 AM on January 4, 2023: member

    ACK f2fc03ec856d7d19a20c482514350cced38f9504 Verified no values are being changed.

  61. maflcko commented at 4:29 PM on January 5, 2023: member

    Checked that f2fc03ec856d7d19a20c482514350cced38f9504 does not change the binary on my system with my compiler

  62. maflcko merged this on Jan 5, 2023
  63. maflcko closed this on Jan 5, 2023

  64. sidhujag referenced this in commit 864cda4aa1 on Jan 6, 2023
  65. fanquake cross-referenced this on Feb 8, 2023 from issue docs: avoid C-style casts; use modern C++ casts by PastaPastaPasta
  66. PastaPastaPasta deleted the branch on Feb 19, 2023
  67. bitcoin locked this on Feb 19, 2024

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-05-20 06:53 UTC