Skip to content

Commit 51512f9

Browse files
authored
Merge pull request #289 from libtom/static-assert
add MP_STATIC_ASSERT
2 parents 07c1898 + 18f6e46 commit 51512f9

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

bn_mp_shrink.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
/* shrink a bignum */
77
mp_err mp_shrink(mp_int *a)
88
{
9-
static int static_check[-(MP_PREC < MP_MIN_PREC)];
109
mp_digit *tmp;
1110
int alloc = MP_MAX(MP_MIN_PREC, a->used);
12-
(void)static_check;
1311
if (a->alloc != alloc) {
1412
if ((tmp = (mp_digit *) MP_REALLOC(a->dp,
1513
(size_t)a->alloc * sizeof(mp_digit),

tommath_private.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ typedef private_mp_word mp_word;
151151
#define MP_MIN(x, y) (((x) < (y)) ? (x) : (y))
152152
#define MP_MAX(x, y) (((x) > (y)) ? (x) : (y))
153153

154+
/* Static assertion */
155+
#define MP_STATIC_ASSERT(msg, cond) typedef char mp_static_assert_##msg[-(!(cond))];
156+
154157
/* ---> Basic Manipulations <--- */
155158
#define MP_IS_ZERO(a) ((a)->used == 0)
156159
#define MP_IS_EVEN(a) (((a)->used == 0) || (((a)->dp[0] & 1u) == 0u))
@@ -162,6 +165,8 @@ typedef private_mp_word mp_word;
162165
/* Minimum number of available digits in mp_int, MP_PREC >= MP_MIN_PREC */
163166
#define MP_MIN_PREC ((((CHAR_BIT * (int)sizeof(long long)) + MP_DIGIT_BIT) - 1) / MP_DIGIT_BIT)
164167

168+
MP_STATIC_ASSERT(prec_geq_min_prec, MP_PREC >= MP_MIN_PREC)
169+
165170
/* random number source */
166171
extern MP_PRIVATE mp_err(*s_mp_rand_source)(void *out, size_t size);
167172

0 commit comments

Comments
 (0)