Commit 07c1898754daab43d6208e96a52117d34d17c86a

Steffen Jaeckel 2019-05-22T11:53:57

Merge pull request #287 from fperrad/20190522_lint some linting

diff --git a/bn_mp_and.c b/bn_mp_and.c
index 1ee14e8..c259f8d 100644
--- a/bn_mp_and.c
+++ b/bn_mp_and.c
@@ -9,7 +9,7 @@ mp_err mp_and(const mp_int *a, const mp_int *b, mp_int *c)
    int used = MP_MAX(a->used, b->used) + 1, i;
    mp_err err;
    mp_digit ac = 1, bc = 1, cc = 1;
-   mp_sign csign = (a->sign == MP_NEG && b->sign == MP_NEG) ? MP_NEG : MP_ZPOS;
+   mp_sign csign = ((a->sign == MP_NEG) && (b->sign == MP_NEG)) ? MP_NEG : MP_ZPOS;
 
    if (c->alloc < used) {
       if ((err = mp_grow(c, used)) != MP_OKAY) {
@@ -22,20 +22,20 @@ mp_err mp_and(const mp_int *a, const mp_int *b, mp_int *c)
 
       /* convert to two complement if negative */
       if (a->sign == MP_NEG) {
-         ac += i >= a->used ? MP_MASK : ~a->dp[i] & MP_MASK;
+         ac += (i >= a->used) ? MP_MASK : (~a->dp[i] & MP_MASK);
          x = ac & MP_MASK;
          ac >>= MP_DIGIT_BIT;
       } else {
-         x = i >= a->used ? 0 : a->dp[i];
+         x = (i >= a->used) ? 0uL : a->dp[i];
       }
 
       /* convert to two complement if negative */
       if (b->sign == MP_NEG) {
-         bc += i >= b->used ? MP_MASK : ~b->dp[i] & MP_MASK;
+         bc += (i >= b->used) ? MP_MASK : (~b->dp[i] & MP_MASK);
          y = bc & MP_MASK;
          bc >>= MP_DIGIT_BIT;
       } else {
-         y = i >= b->used ? 0 : b->dp[i];
+         y = (i >= b->used) ? 0uL : b->dp[i];
       }
 
       c->dp[i] = x & y;
diff --git a/bn_mp_count_bits.c b/bn_mp_count_bits.c
index bba9a94..b7c2cad 100644
--- a/bn_mp_count_bits.c
+++ b/bn_mp_count_bits.c
@@ -19,9 +19,9 @@ int mp_count_bits(const mp_int *a)
 
    /* take the last digit and count the bits in it */
    q = a->dp[a->used - 1];
-   while (q > (mp_digit)0) {
+   while (q > 0u) {
       ++r;
-      q >>= (mp_digit)1;
+      q >>= 1u;
    }
    return r;
 }
diff --git a/bn_mp_fread.c b/bn_mp_fread.c
index 04a1316..52ea773 100644
--- a/bn_mp_fread.c
+++ b/bn_mp_fread.c
@@ -49,7 +49,7 @@ mp_err mp_fread(mp_int *a, int radix, FILE *stream)
       }
    } while ((ch = fgetc(stream)) != EOF);
 
-   if (!mp_iszero(a)) {
+   if (a->used != 0) {
       a->sign = neg;
    }
 
diff --git a/bn_mp_ilogb.c b/bn_mp_ilogb.c
index efcd5f9..0ca0193 100644
--- a/bn_mp_ilogb.c
+++ b/bn_mp_ilogb.c
@@ -24,10 +24,10 @@ static mp_digit s_digit_ilogb(mp_digit base, mp_digit n)
    mp_digit ret, high = 1uL, low = 0uL, mid;
 
    if (n < base) {
-      return (mp_digit)0uL;
+      return 0uL;
    }
    if (n == base) {
-      return (mp_digit)1uL;
+      return 1uL;
    }
 
    bracket_high = (mp_word) base ;
diff --git a/bn_mp_or.c b/bn_mp_or.c
index 6102a8a..cdacbfb 100644
--- a/bn_mp_or.c
+++ b/bn_mp_or.c
@@ -9,7 +9,7 @@ mp_err mp_or(const mp_int *a, const mp_int *b, mp_int *c)
    int used = MP_MAX(a->used, b->used) + 1, i;
    mp_err err;
    mp_digit ac = 1, bc = 1, cc = 1;
-   mp_sign csign = (a->sign == MP_NEG || b->sign == MP_NEG) ? MP_NEG : MP_ZPOS;
+   mp_sign csign = ((a->sign == MP_NEG) || (b->sign == MP_NEG)) ? MP_NEG : MP_ZPOS;
 
    if (c->alloc < used) {
       if ((err = mp_grow(c, used)) != MP_OKAY) {
@@ -22,20 +22,20 @@ mp_err mp_or(const mp_int *a, const mp_int *b, mp_int *c)
 
       /* convert to two complement if negative */
       if (a->sign == MP_NEG) {
-         ac += i >= a->used ? MP_MASK : ~a->dp[i] & MP_MASK;
+         ac += (i >= a->used) ? MP_MASK : (~a->dp[i] & MP_MASK);
          x = ac & MP_MASK;
          ac >>= MP_DIGIT_BIT;
       } else {
-         x = i >= a->used ? 0 : a->dp[i];
+         x = (i >= a->used) ? 0uL : a->dp[i];
       }
 
       /* convert to two complement if negative */
       if (b->sign == MP_NEG) {
-         bc += i >= b->used ? MP_MASK : ~b->dp[i] & MP_MASK;
+         bc += (i >= b->used) ? MP_MASK : (~b->dp[i] & MP_MASK);
          y = bc & MP_MASK;
          bc >>= MP_DIGIT_BIT;
       } else {
-         y = i >= b->used ? 0 : b->dp[i];
+         y = (i >= b->used) ? 0uL : b->dp[i];
       }
 
       c->dp[i] = x | y;
diff --git a/bn_mp_xor.c b/bn_mp_xor.c
index c066e65..71e7ca1 100644
--- a/bn_mp_xor.c
+++ b/bn_mp_xor.c
@@ -22,20 +22,20 @@ mp_err mp_xor(const mp_int *a, const mp_int *b, mp_int *c)
 
       /* convert to two complement if negative */
       if (a->sign == MP_NEG) {
-         ac += i >= a->used ? MP_MASK : ~a->dp[i] & MP_MASK;
+         ac += (i >= a->used) ? MP_MASK : (~a->dp[i] & MP_MASK);
          x = ac & MP_MASK;
          ac >>= MP_DIGIT_BIT;
       } else {
-         x = i >= a->used ? 0 : a->dp[i];
+         x = (i >= a->used) ? 0uL : a->dp[i];
       }
 
       /* convert to two complement if negative */
       if (b->sign == MP_NEG) {
-         bc += i >= b->used ? MP_MASK : ~b->dp[i] & MP_MASK;
+         bc += (i >= b->used) ? MP_MASK : (~b->dp[i] & MP_MASK);
          y = bc & MP_MASK;
          bc >>= MP_DIGIT_BIT;
       } else {
-         y = i >= b->used ? 0 : b->dp[i];
+         y = (i >= b->used) ? 0uL : b->dp[i];
       }
 
       c->dp[i] = x ^ y;
diff --git a/bn_s_mp_toom_mul.c b/bn_s_mp_toom_mul.c
index e80b6f6..ce47f25 100644
--- a/bn_s_mp_toom_mul.c
+++ b/bn_s_mp_toom_mul.c
@@ -63,7 +63,7 @@ mp_err s_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c)
       goto LTM_ERRa2;
    }
    for (; count < a->used; count++) {
-      a2.dp[count - 2 * B] = a->dp[count];
+      a2.dp[count - (2 * B)] = a->dp[count];
       a2.used++;
    }
 
@@ -88,7 +88,7 @@ mp_err s_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c)
       goto LTM_ERRb2;
    }
    for (; count < b->used; count++) {
-      b2.dp[count - 2 * B] = b->dp[count];
+      b2.dp[count - (2 * B)] = b->dp[count];
       b2.used++;
    }
 
diff --git a/tommath_class.h b/tommath_class.h
index 5f148cd..b72f545 100644
--- a/tommath_class.h
+++ b/tommath_class.h
@@ -401,7 +401,6 @@
 #   define BN_MP_ZERO_C
 #   define BN_MP_MUL_D_C
 #   define BN_MP_ADD_D_C
-#   define BN_MP_ISZERO_C
 #endif
 
 #if defined(BN_MP_FWRITE_C)