Skip to content

Commit c0041b5

Browse files
Add static assertion that uint32_t is unsigned int or wider
1 parent 4ad408f commit c0041b5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/assumptions.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#ifndef SECP256K1_ASSUMPTIONS_H
88
#define SECP256K1_ASSUMPTIONS_H
99

10+
#include <limits.h>
11+
1012
#include "util.h"
1113

1214
/* This library, like most software, relies on a number of compiler implementation defined (but not undefined)
@@ -19,7 +21,11 @@ struct secp256k1_assumption_checker {
1921
allowed. */
2022
int dummy_array[(
2123
/* Bytes are 8 bits. */
22-
CHAR_BIT == 8 &&
24+
(CHAR_BIT == 8) &&
25+
26+
/* No integer promotion for uint32_t. This ensures that we can multiply uintXX_t values where XX >= 32
27+
without signed overflow, which would be undefined behaviour. */
28+
(UINT_MAX <= UINT32_MAX) &&
2329

2430
/* Conversions from unsigned to signed outside of the bounds of the signed type are
2531
implementation-defined. Verify that they function as reinterpreting the lower

0 commit comments

Comments
 (0)