Commit c99a88e79007e83bbf7c4114428dfa423737cd1b

Steffen Jaeckel 2019-05-21T23:03:48

Merge pull request #266 from fperrad/20190517_lint more linting

diff --git a/bn_deprecated.c b/bn_deprecated.c
index 90a4064..ca930d6 100644
--- a/bn_deprecated.c
+++ b/bn_deprecated.c
@@ -9,7 +9,7 @@ int mp_get_bit(const mp_int *a, int b)
    if (b < 0) {
       return MP_VAL;
    }
-   return s_mp_get_bit(a, (unsigned int)b) == MP_YES ? MP_YES : MP_NO;
+   return (s_mp_get_bit(a, (unsigned int)b) == MP_YES) ? MP_YES : MP_NO;
 }
 #endif
 #ifdef BN_S_MP_JACOBI_C
diff --git a/bn_mp_cmp_mag.c b/bn_mp_cmp_mag.c
index 315a826..f144ea9 100644
--- a/bn_mp_cmp_mag.c
+++ b/bn_mp_cmp_mag.c
@@ -7,7 +7,7 @@
 mp_ord mp_cmp_mag(const mp_int *a, const mp_int *b)
 {
    int     n;
-   mp_digit *tmpa, *tmpb;
+   const mp_digit *tmpa, *tmpb;
 
    /* compare based on # of non-zero digits */
    if (a->used > b->used) {
diff --git a/bn_mp_fwrite.c b/bn_mp_fwrite.c
index 744e5ff..2a59755 100644
--- a/bn_mp_fwrite.c
+++ b/bn_mp_fwrite.c
@@ -24,7 +24,7 @@ mp_err mp_fwrite(const mp_int *a, int radix, FILE *stream)
       return err;
    }
 
-   if (fwrite(buf, (size_t)len, 1, stream) != 1) {
+   if (fwrite(buf, (size_t)len, 1uL, stream) != 1uL) {
       MP_FREE_BUFFER(buf, (size_t)len);
       return MP_ERR;
    }
diff --git a/bn_mp_prime_next_prime.c b/bn_mp_prime_next_prime.c
index f5ce9eb..e8cc2e2 100644
--- a/bn_mp_prime_next_prime.c
+++ b/bn_mp_prime_next_prime.c
@@ -68,7 +68,7 @@ mp_err mp_prime_next_prime(mp_int *a, int t, int bbs_style)
       if ((a->dp[0] & 3u) != 3u) {
          if ((err = mp_sub_d(a, (a->dp[0] & 3u) + 1u, a)) != MP_OKAY) {
             return err;
-         };
+         }
       }
    } else {
       if (MP_IS_EVEN(a)) {
diff --git a/tommath_private.h b/tommath_private.h
index 260062f..67ac014 100644
--- a/tommath_private.h
+++ b/tommath_private.h
@@ -82,8 +82,8 @@ do {                                                    \
 do {                                                    \
    size_t zs_ = (size);                                 \
    char* zm_ = (char*)(mem);                            \
-   while (zs_-- > 0) {                                  \
-      *zm_++ = 0;                                       \
+   while (zs_-- > 0u) {                                 \
+      *zm_++ = '\0';                                    \
    }                                                    \
 } while (0)
 #  define MP_ZERO_DIGITS(mem, digits)                   \
@@ -156,7 +156,7 @@ typedef private_mp_word mp_word;
 #define MP_IS_EVEN(a) (((a)->used == 0) || (((a)->dp[0] & 1u) == 0u))
 #define MP_IS_ODD(a)  (((a)->used > 0) && (((a)->dp[0] & 1u) == 1u))
 
-#define MP_SIZEOF_BITS(type)    (CHAR_BIT * sizeof(type))
+#define MP_SIZEOF_BITS(type)    ((size_t)CHAR_BIT * sizeof(type))
 #define MP_MAXFAST              (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT)))
 
 /* Minimum number of available digits in mp_int, MP_PREC >= MP_MIN_PREC */