Skip to content

Commit

Permalink
Add static assertion that uint32_t is unsigned int or wider
Browse files Browse the repository at this point in the history
Summary:
This is a backport of secp256k1 [[bitcoin-core/secp256k1#818 | PR818]]

Depends on D7632

Test Plan:
  ninja check-secp256k1

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D7635
  • Loading branch information
real-or-random authored and deadalnix committed Sep 29, 2020
1 parent 35167d3 commit 7ccaa00
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/secp256k1/src/assumptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#ifndef SECP256K1_ASSUMPTIONS_H
#define SECP256K1_ASSUMPTIONS_H

#include <limits.h>

#include "util.h"

/* This library, like most software, relies on a number of compiler implementation defined (but not undefined)
Expand All @@ -19,7 +21,11 @@ struct secp256k1_assumption_checker {
allowed. */
int dummy_array[(
/* Bytes are 8 bits. */
CHAR_BIT == 8 &&
(CHAR_BIT == 8) &&

/* No integer promotion for uint32_t. This ensures that we can multiply uintXX_t values where XX >= 32
without signed overflow, which would be undefined behaviour. */
(UINT_MAX <= UINT32_MAX) &&

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

0 comments on commit 7ccaa00

Please sign in to comment.