serialize: Document integer width assumptions we are making when calculating compact sizes #14475

pull practicalswift wants to merge 1 commits into bitcoin:master from practicalswift:integer-width-assumptions changing 1 files +2 −0
  1. practicalswift commented at 2:47 PM on October 13, 2018: contributor
    • Document integer width assumptions we are making when calculating compact sizes
    • Document floating-point width assumptions we are making in the serialization code

    Rationale:

    • Explicit is better than implicit
    • Compile-time failure is better than run time failure :-)
  2. fanquake added the label Refactoring on Oct 13, 2018
  3. practicalswift force-pushed on Oct 13, 2018
  4. serialize: Document integer width assumptions we are making when calculating compact sizes 4486f2ad08
  5. practicalswift force-pushed on Oct 13, 2018
  6. practicalswift renamed this:
    serialize: Document integer width assumptions we are making when calculating compact sizes
    serialize: Document width assumptions we are making in the serialization code
    on Oct 13, 2018
  7. hebasto commented at 4:11 PM on October 13, 2018: member

    utACK 25ae1a1

  8. practicalswift force-pushed on Oct 14, 2018
  9. practicalswift renamed this:
    serialize: Document width assumptions we are making in the serialization code
    serialize: Document integer width assumptions we are making when calculating compact sizes
    on Oct 14, 2018
  10. practicalswift commented at 11:35 AM on October 14, 2018: contributor

    @hebasto Updated. Please re-review :-)

  11. hebasto commented at 2:45 PM on October 14, 2018: member

    Let's assume a platform with sizeof(short) > 2 or sizeof(int) > 4. Without static_assert statement the logic will remain correct if nSize <= std::numeric_limits<unsigned short>::max() replace with nSize <= 0xffff and nSize <= std::numeric_limits<unsigned int>::max() replace with nSize <= 0xffffffff

  12. practicalswift commented at 4:43 PM on October 14, 2018: contributor

    @hebasto As I read the code more adjustments would be needed to the serialisation code to make it work properly under such a platform. I don't think changing GetSizeOfCompactSize and WriteCompactSize would be enough?

    FWIW I think the platform requirements are reasonable. My goal with this PR is just making the platform requirements explicit and immediately obvious to compilers, humans and static analysers :-)

    I think a compile time check is the most elegant and non-intrusive way to achieve that goal.

  13. hebasto commented at 4:02 PM on October 15, 2018: member

    FWIW I think the platform requirements are reasonable. My goal with this PR is just making the platform requirements explicit and immediately obvious to compilers, humans and static analysers :-)

    I think a compile time check is the most elegant and non-intrusive way to achieve that goal.

    Agree. ACK 4486f2a

  14. practicalswift closed this on Oct 19, 2018

  15. practicalswift deleted the branch on Apr 10, 2021
  16. 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-13 21:15 UTC

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