Commit 0018bf4a92533ee9ae2b127cc4d3f31b9552b8eb

Steffen Jaeckel 2019-10-06T21:09:50

Merge pull request #358 from fperrad/20191006_lint some linting

diff --git a/bn_mp_from_sbin.c b/bn_mp_from_sbin.c
index 780639a..20e4597 100644
--- a/bn_mp_from_sbin.c
+++ b/bn_mp_from_sbin.c
@@ -4,17 +4,17 @@
 /* SPDX-License-Identifier: Unlicense */
 
 /* read signed bin, big endian, first byte is 0==positive or 1==negative */
-mp_err mp_from_sbin(mp_int *a, const unsigned char *b, size_t c)
+mp_err mp_from_sbin(mp_int *a, const unsigned char *buf, size_t size)
 {
    mp_err err;
 
    /* read magnitude */
-   if ((err = mp_from_ubin(a, b + 1, c - 1u)) != MP_OKAY) {
+   if ((err = mp_from_ubin(a, buf + 1, size - 1u)) != MP_OKAY) {
       return err;
    }
 
    /* first byte is 0 for positive, non-zero for negative */
-   if (b[0] == (unsigned char)0) {
+   if (buf[0] == (unsigned char)0) {
       a->sign = MP_ZPOS;
    } else {
       a->sign = MP_NEG;
diff --git a/bn_mp_from_ubin.c b/bn_mp_from_ubin.c
index 78a4cf1..7f73cbc 100644
--- a/bn_mp_from_ubin.c
+++ b/bn_mp_from_ubin.c
@@ -4,7 +4,7 @@
 /* SPDX-License-Identifier: Unlicense */
 
 /* reads a unsigned char array, assumes the msb is stored first [big endian] */
-mp_err mp_from_ubin(mp_int *a, const unsigned char *b, size_t size)
+mp_err mp_from_ubin(mp_int *a, const unsigned char *buf, size_t size)
 {
    mp_err err;
 
@@ -25,11 +25,11 @@ mp_err mp_from_ubin(mp_int *a, const unsigned char *b, size_t size)
       }
 
 #ifndef MP_8BIT
-      a->dp[0] |= *b++;
+      a->dp[0] |= *buf++;
       a->used += 1;
 #else
-      a->dp[0] = (*b & MP_MASK);
-      a->dp[1] |= ((*b++ >> 7) & 1u);
+      a->dp[0] = (*buf & MP_MASK);
+      a->dp[1] |= ((*buf++ >> 7) & 1u);
       a->used += 2;
 #endif
    }
diff --git a/bn_mp_to_sbin.c b/bn_mp_to_sbin.c
index b736f98..e28dcce 100644
--- a/bn_mp_to_sbin.c
+++ b/bn_mp_to_sbin.c
@@ -4,20 +4,20 @@
 /* SPDX-License-Identifier: Unlicense */
 
 /* store in signed [big endian] format */
-mp_err mp_to_sbin(const mp_int *a, unsigned char *b, size_t maxlen, size_t *written)
+mp_err mp_to_sbin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written)
 {
    mp_err err;
    if (maxlen == 0u) {
       return MP_VAL;
    }
 
-   if ((err = mp_to_ubin(a, b + 1, maxlen - 1u, written)) != MP_OKAY) {
+   if ((err = mp_to_ubin(a, buf + 1, maxlen - 1u, written)) != MP_OKAY) {
       return err;
    }
    if (written != NULL) {
       (*written)++;
    }
-   b[0] = (a->sign == MP_ZPOS) ? (unsigned char)0 : (unsigned char)1;
+   buf[0] = (a->sign == MP_ZPOS) ? (unsigned char)0 : (unsigned char)1;
    return MP_OKAY;
 }
 #endif
diff --git a/bn_mp_to_ubin.c b/bn_mp_to_ubin.c
index 80c14ab..d359986 100644
--- a/bn_mp_to_ubin.c
+++ b/bn_mp_to_ubin.c
@@ -4,13 +4,13 @@
 /* SPDX-License-Identifier: Unlicense */
 
 /* store in unsigned [big endian] format */
-mp_err mp_to_ubin(const mp_int *a, unsigned char *b, size_t maxlen, size_t *written)
+mp_err mp_to_ubin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *written)
 {
    size_t    x;
    mp_err  err;
    mp_int  t;
 
-   if (b == NULL) {
+   if (buf == NULL) {
       return MP_MEM;
    }
 
@@ -26,20 +26,19 @@ mp_err mp_to_ubin(const mp_int *a, unsigned char *b, size_t maxlen, size_t *writ
    while (!MP_IS_ZERO(&t)) {
       if (maxlen == 0u) {
          err = MP_VAL;
-         break;
+         goto LBL_ERR;
       }
       maxlen--;
 #ifndef MP_8BIT
-      b[x++] = (unsigned char)(t.dp[0] & 255u);
+      buf[x++] = (unsigned char)(t.dp[0] & 255u);
 #else
-      b[x++] = (unsigned char)(t.dp[0] | ((t.dp[1] & 1u) << 7));
+      buf[x++] = (unsigned char)(t.dp[0] | ((t.dp[1] & 1u) << 7));
 #endif
       if ((err = mp_div_2d(&t, 8, &t, NULL)) != MP_OKAY) {
          goto LBL_ERR;
       }
    }
-   s_mp_reverse(b, x);
-   err = MP_OKAY;
+   s_mp_reverse(buf, x);
 
    if (written != NULL) {
       *written = x;
diff --git a/bn_mp_ubin_size.c b/bn_mp_ubin_size.c
index f32e190..21230b4 100644
--- a/bn_mp_ubin_size.c
+++ b/bn_mp_ubin_size.c
@@ -6,8 +6,7 @@
 /* get the size for an unsigned equivalent */
 size_t mp_ubin_size(const mp_int *a)
 {
-   int     size = mp_count_bits(a);
-   size = (size / 8) + ((((unsigned)size & 7u) != 0u) ? 1 : 0);
-   return (size_t)size;
+   size_t size = (size_t)mp_count_bits(a);
+   return (size / 8u) + (((size & 7u) != 0u) ? 1u : 0u);
 }
 #endif
diff --git a/bn_s_mp_reverse.c b/bn_s_mp_reverse.c
index 623d51e..c549e60 100644
--- a/bn_s_mp_reverse.c
+++ b/bn_s_mp_reverse.c
@@ -9,8 +9,8 @@ void s_mp_reverse(unsigned char *s, size_t len)
    size_t   ix, iy;
    unsigned char t;
 
-   ix = 0;
-   iy = len - 1;
+   ix = 0u;
+   iy = len - 1u;
    while (ix < iy) {
       t     = s[ix];
       s[ix] = s[iy];