Add static assertion that uint32_t is unsigned int or wider #818
pull real-or-random wants to merge 1 commits into bitcoin-core:master from real-or-random:202009_assert_sizeof_int changing 1 files +7 −1-
real-or-random commented at 11:36 am on September 17, 2020: contributorSolves one item in #792 .
-
Add static assertion that uint32_t is unsigned int or wider c0041b5cfc
-
in src/assumptions.h:28 in c0041b5cfc
20@@ -19,7 +21,11 @@ struct secp256k1_assumption_checker { 21 allowed. */ 22 int dummy_array[( 23 /* Bytes are 8 bits. */ 24- CHAR_BIT == 8 && 25+ (CHAR_BIT == 8) && 26+ 27+ /* No integer promotion for uint32_t. This ensures that we can multiply uintXX_t values where XX >= 32 28+ without signed overflow, which would be undefined behaviour. */ 29+ (UINT_MAX <= UINT32_MAX) &&
roconnor-blockstream commented at 2:50 pm on September 17, 2020:I thinkINT_MAX < UINT32_MAX
would more directly capture your intention here; however given the other rules of C, I do admit that what you have written ends up being equivalent.
real-or-random commented at 11:42 am on September 18, 2020:Yeah, I think our intuition is just different. My thought was that ifuint32_t
is at least as large asunsigned int
, then no promotion can happen at all, neither tosigned int
nor tounsigned int
.
roconnor-blockstream commented at 12:06 pm on September 18, 2020:I think of the rule as if every value of a type can fit within asigned int
, then it is subject to integer promotion.
sipa commented at 8:52 pm on September 18, 2020:Both seem reasonable and harmless to me.
real-or-random commented at 9:56 am on September 19, 2020:Wanna ACK then?elichai approvedelichai commented at 7:40 am on September 21, 2020: contributorLooks good. ACK c0041b5cfca5efb160aa9a5616350069c89a8c29sipa commented at 3:41 am on September 26, 2020: contributorutACK c0041b5cfca5efb160aa9a5616350069c89a8c29real-or-random merged this on Sep 26, 2020real-or-random closed this on Sep 26, 2020
jasonbcox referenced this in commit 7ccaa00435 on Sep 29, 2020deadalnix referenced this in commit 7516ca138d on Sep 30, 2020
github-metadata-mirror
This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-22 14:15 UTC
This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-12-22 14:15 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me
More mirrored repositories can be found on mirror.b10c.me