From d0e26bb3ff18c31f1446b0620626187ad2ca8ffb Mon Sep 17 00:00:00 2001 From: Francois Perrad Date: Thu, 24 Oct 2019 18:26:25 +0200 Subject: [PATCH 1/4] explicit operator precedence --- mp_div.c | 2 +- mp_log_u32.c | 2 +- tommath_private.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mp_div.c b/mp_div.c index 5fd9572..e9f4f50 100644 --- a/mp_div.c +++ b/mp_div.c @@ -27,7 +27,7 @@ mp_err mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d) if (MP_HAS(S_MP_DIV_RECURSIVE) && (b->used > MP_KARATSUBA_MUL_CUTOFF) - && (b->used <= ((a->used)/3*2))) { + && (b->used <= ((a->used/3)*2))) { err = s_mp_div_recursive(a, b, c, d); } else if (MP_HAS(S_MP_DIV_SCHOOL)) { err = s_mp_div_school(a, b, c, d); diff --git a/mp_log_u32.c b/mp_log_u32.c index 5568568..cff9e48 100644 --- a/mp_log_u32.c +++ b/mp_log_u32.c @@ -17,7 +17,7 @@ mp_err mp_log_u32(const mp_int *a, uint32_t base, uint32_t *c) return MP_VAL; } - if (MP_HAS(S_MP_LOG_POW2) && (base & (base - 1u)) == 0u) { + if (MP_HAS(S_MP_LOG_POW2) && ((base & (base - 1u)) == 0u)) { *c = s_mp_log_pow2(a, base); return MP_OKAY; } diff --git a/tommath_private.h b/tommath_private.h index f3aeb8f..1911747 100644 --- a/tommath_private.h +++ b/tommath_private.h @@ -167,7 +167,7 @@ typedef unsigned long mp_word __attribute__((mode(TI))); typedef uint64_t mp_word; #endif -MP_STATIC_ASSERT(correct_word_size, sizeof(mp_word) == 2 * sizeof(mp_digit)) +MP_STATIC_ASSERT(correct_word_size, sizeof(mp_word) == (2 * sizeof(mp_digit))) /* default precision */ #ifndef MP_PREC From 9051694850645bad6fc3aa9cc92209edc6f8eb85 Mon Sep 17 00:00:00 2001 From: Francois Perrad Date: Thu, 24 Oct 2019 18:11:36 +0200 Subject: [PATCH 2/4] literal suffix --- s_mp_div_recursive.c | 4 ++-- tommath_private.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/s_mp_div_recursive.c b/s_mp_div_recursive.c index 67b4a05..d641123 100644 --- a/s_mp_div_recursive.c +++ b/s_mp_div_recursive.c @@ -48,7 +48,7 @@ static mp_err s_mp_recursion(const mp_int *a, const mp_int *b, mp_int *q, mp_int /* while A1 < 0 do Q1 = Q1 - 1, A1 = A1 + (beta^k * B) */ if ((err = mp_mul_2d(b, k * MP_DIGIT_BIT, &t)) != MP_OKAY) goto LBL_ERR; - while (mp_cmp_d(&A1, 0) == MP_LT) { + while (mp_cmp_d(&A1, 0uL) == MP_LT) { if ((err = mp_decr(&Q1)) != MP_OKAY) goto LBL_ERR; if ((err = mp_add(&A1, &t, &A1)) != MP_OKAY) goto LBL_ERR; } @@ -64,7 +64,7 @@ static mp_err s_mp_recursion(const mp_int *a, const mp_int *b, mp_int *q, mp_int if ((err = mp_sub(&A2, &t, &A2)) != MP_OKAY) goto LBL_ERR; /* while A2 < 0 do Q0 = Q0 - 1, A2 = A2 + B */ - while (mp_cmp_d(&A2, 0) == MP_LT) { + while (mp_cmp_d(&A2, 0uL) == MP_LT) { if ((err = mp_decr(&Q0)) != MP_OKAY) goto LBL_ERR; if ((err = mp_add(&A2, b, &A2)) != MP_OKAY) goto LBL_ERR; } diff --git a/tommath_private.h b/tommath_private.h index 1911747..a03ae41 100644 --- a/tommath_private.h +++ b/tommath_private.h @@ -167,7 +167,7 @@ typedef unsigned long mp_word __attribute__((mode(TI))); typedef uint64_t mp_word; #endif -MP_STATIC_ASSERT(correct_word_size, sizeof(mp_word) == (2 * sizeof(mp_digit))) +MP_STATIC_ASSERT(correct_word_size, sizeof(mp_word) == (2u * sizeof(mp_digit))) /* default precision */ #ifndef MP_PREC From 17afe155f0e40d3b39e1bb5fa706b2bad5261d39 Mon Sep 17 00:00:00 2001 From: Francois Perrad Date: Thu, 24 Oct 2019 18:16:05 +0200 Subject: [PATCH 3/4] needs mp_word --- etc/pprime.c | 1 + 1 file changed, 1 insertion(+) diff --git a/etc/pprime.c b/etc/pprime.c index 411e446..fe32a30 100644 --- a/etc/pprime.c +++ b/etc/pprime.c @@ -7,6 +7,7 @@ #include #include #include "tommath.h" +#include "tommath_private.h" /* mp_word */ static int n_prime; static FILE *primes; From c4622f53c8f399f8451743c007399139dea930d4 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Thu, 24 Oct 2019 21:44:55 +0200 Subject: [PATCH 4/4] only include tommath_private.h --- etc/pprime.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/etc/pprime.c b/etc/pprime.c index fe32a30..1d59cab 100644 --- a/etc/pprime.c +++ b/etc/pprime.c @@ -6,8 +6,7 @@ */ #include #include -#include "tommath.h" -#include "tommath_private.h" /* mp_word */ +#include "tommath_private.h" static int n_prime; static FILE *primes;