Commit f55f0a9ef58bd7ae541bad21f9852bc548b85bc3

Daniel Mendler 2019-05-18T09:28:33

fix some usages of enum types

diff --git a/bn_mp_ilogb.c b/bn_mp_ilogb.c
index d72c952..efcd5f9 100644
--- a/bn_mp_ilogb.c
+++ b/bn_mp_ilogb.c
@@ -73,7 +73,7 @@ static mp_digit s_digit_ilogb(mp_digit base, mp_digit n)
 mp_err mp_ilogb(const mp_int *a, mp_digit base, mp_int *c)
 {
    mp_err err;
-   int cmp;
+   mp_ord cmp;
    unsigned int high, low, mid;
    mp_int bracket_low, bracket_high, bracket_mid, t, bi_base;
    mp_digit tmp;
@@ -90,8 +90,7 @@ mp_err mp_ilogb(const mp_int *a, mp_digit base, mp_int *c)
       return MP_VAL;
    }
    if (base == 2u) {
-      cmp = mp_count_bits(a) - 1;
-      mp_set_int(c, (unsigned long)cmp);
+      mp_set_int(c, (unsigned long)(mp_count_bits(a) - 1));
       return err;
    }
    if (a->used == 1) {
diff --git a/bn_mp_n_root_ex.c b/bn_mp_n_root_ex.c
index c37f575..8705c6a 100644
--- a/bn_mp_n_root_ex.c
+++ b/bn_mp_n_root_ex.c
@@ -15,7 +15,7 @@
 mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
 {
    mp_int t1, t2, t3, a_;
-   int    cmp;
+   mp_ord cmp;
    int    ilog2;
    mp_err res;
 
diff --git a/bn_mp_prime_is_prime.c b/bn_mp_prime_is_prime.c
index db94dec..e3f2436 100644
--- a/bn_mp_prime_is_prime.c
+++ b/bn_mp_prime_is_prime.c
@@ -51,7 +51,7 @@ mp_err mp_prime_is_prime(const mp_int *a, int t, mp_bool *result)
    if ((err = mp_is_square(a, &res)) != MP_OKAY) {
       return err;
    }
-   if (res != 0) {
+   if (res != MP_NO) {
       return MP_OKAY;
    }
 
diff --git a/bn_mp_prime_strong_lucas_selfridge.c b/bn_mp_prime_strong_lucas_selfridge.c
index f30179c..389f62d 100644
--- a/bn_mp_prime_strong_lucas_selfridge.c
+++ b/bn_mp_prime_strong_lucas_selfridge.c
@@ -72,7 +72,7 @@ mp_err mp_prime_strong_lucas_selfridge(const mp_int *a, mp_bool *result)
    /* CZ TODO: Some of them need the full 32 bit, hence the (temporary) exclusion of MP_8BIT */
    int32_t D, Ds, J, sign, P, Q, r, s, u, Nbits;
    mp_err e;
-   int oddness;
+   mp_bool oddness;
 
    *result = MP_NO;
    /*
diff --git a/callgraph.txt b/callgraph.txt
index a5eea03..4eb61ea 100644
--- a/callgraph.txt
+++ b/callgraph.txt
@@ -2533,9 +2533,9 @@ BN_MP_GROW_C
 
 
 BN_MP_ILOGB_C
-+--->BN_MP_COUNT_BITS_C
 +--->BN_MP_SET_INT_C
 |   +--->BN_MP_SET_LONG_C
++--->BN_MP_COUNT_BITS_C
 +--->BN_MP_SET_C
 |   +--->BN_MP_ZERO_C
 +--->BN_MP_CMP_D_C
diff --git a/demo/test.c b/demo/test.c
index 9457487..69c8fbc 100644
--- a/demo/test.c
+++ b/demo/test.c
@@ -148,8 +148,8 @@ static int test_s_mp_jacobi(void)
       { 9, { -1,  1,  0,  1,  1,  0,  1,  1,  0,  1,  1,  0,  1,  1,  0,  1 } },
    };
 
-   int i, n, should, cnt;
-   mp_err err;
+   int i, n, cnt;
+   mp_err err, should;
    mp_int a, b;
    if (mp_init_multi(&a, &b, NULL)!= MP_OKAY) {
       return EXIT_FAILURE;
@@ -1267,9 +1267,10 @@ LBL_ERR:
 }
 /* stripped down version of mp_radix_size. The faster version can be off by up t
 o +3  */
-static int s_rs(const mp_int *a, int radix, int *size)
+static mp_err s_rs(const mp_int *a, int radix, int *size)
 {
-   int     res, digs = 0;
+   mp_err res;
+   int digs = 0;
    mp_int  t;
    mp_digit d;
    *size = 0;
@@ -1431,7 +1432,7 @@ LBL_ERR:
 static int test_mp_incr(void)
 {
    mp_int a, b;
-   int e = MP_OKAY;
+   mp_err e = MP_OKAY;
 
    if ((e = mp_init_multi(&a, &b, NULL)) != MP_OKAY) {
       goto LTM_ERR;
@@ -1496,7 +1497,7 @@ LTM_ERR:
 static int test_mp_decr(void)
 {
    mp_int a, b;
-   int e = MP_OKAY;
+   mp_err e = MP_OKAY;
 
    if ((e = mp_init_multi(&a, &b, NULL)) != MP_OKAY) {
       goto LTM_ERR;
@@ -1585,7 +1586,7 @@ LTM_ERR:
 static int test_mp_n_root(void)
 {
    mp_int a, c, r;
-   int e;
+   mp_err e;
    int i, j;
 
    const char *input[] = {
@@ -1803,7 +1804,7 @@ LTM_ERR:
 static int test_s_mp_balance_mul(void)
 {
    mp_int a, b, c;
-   int e = MP_OKAY;
+   mp_err e = MP_OKAY;
 
    const char *na =
       "4b0I5uMTujCysw+1OOuOyH2FX2WymrHUqi8BBDb7XpkV/4i7vXTbEYUy/kdIfCKu5jT5JEqYkdmnn3jAYo8XShPzNLxZx9yoLjxYRyptSuOI2B1DspvbIVYXY12sxPZ4/HCJ4Usm2MU5lO/006KnDMxuxiv1rm6YZJZ0eZU";
diff --git a/tommath_class.h b/tommath_class.h
index 9faa0fa..880ea8b 100644
--- a/tommath_class.h
+++ b/tommath_class.h
@@ -435,8 +435,8 @@
 #endif
 
 #if defined(BN_MP_ILOGB_C)
-#   define BN_MP_COUNT_BITS_C
 #   define BN_MP_SET_INT_C
+#   define BN_MP_COUNT_BITS_C
 #   define BN_MP_SET_C
 #   define BN_MP_CMP_D_C
 #   define BN_MP_ZERO_C