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 :-)
fanquake added the label Refactoring on Oct 13, 2018
practicalswift force-pushed on Oct 13, 2018
serialize: Document integer width assumptions we are making when calculating compact sizes4486f2ad08
practicalswift force-pushed on Oct 13, 2018
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
hebasto
commented at 4:11 PM on October 13, 2018:
member
utACK25ae1a1
practicalswift force-pushed on Oct 14, 2018
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
practicalswift
commented at 11:35 AM on October 14, 2018:
contributor
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
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.
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.
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