Commit 9a8b2ecb025904fbb939eba390a965e350e36a5a

Francois Perrad 2019-05-22T08:16:38

explicit operator precedence

diff --git a/bn_mp_and.c b/bn_mp_and.c
index 1ee14e8..e781f31 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) ? 0 : 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) ? 0 : b->dp[i];
       }
 
       c->dp[i] = x & y;
diff --git a/bn_mp_or.c b/bn_mp_or.c
index 6102a8a..6f09a70 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) ? 0 : 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) ? 0 : b->dp[i];
       }
 
       c->dp[i] = x | y;
diff --git a/bn_mp_xor.c b/bn_mp_xor.c
index c066e65..90958d4 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) ? 0 : 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) ? 0 : 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++;
    }