Merge pull request #125 from fperrad/20180923_lint two-complement: some linting
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
diff --git a/bn_mp_complement.c b/bn_mp_complement.c
index 256ddea..9dfddc3 100644
--- a/bn_mp_complement.c
+++ b/bn_mp_complement.c
@@ -17,7 +17,7 @@
int mp_complement(const mp_int *a, mp_int *b)
{
int res = mp_neg(a, b);
- return res == MP_OKAY ? mp_sub_d(b, 1, b) : res;
+ return (res == MP_OKAY) ? mp_sub_d(b, 1uL, b) : res;
}
#endif
diff --git a/bn_mp_tc_and.c b/bn_mp_tc_and.c
index 0e28ca8..e9fe4c6 100644
--- a/bn_mp_tc_and.c
+++ b/bn_mp_tc_and.c
@@ -17,12 +17,12 @@
int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
{
int res = MP_OKAY, bits;
- int as = mp_isneg(a), bs = mp_isneg(b), s = 0;
- mp_int *mx = 0, _mx, acpy, bcpy;
+ int as = mp_isneg(a), bs = mp_isneg(b);
+ mp_int *mx = NULL, _mx, acpy, bcpy;
- if (as || bs) {
+ if ((as != MP_NO) || (bs != MP_NO)) {
bits = MAX(mp_count_bits(a), mp_count_bits(b));
- res = mp_init_set_int(&_mx, 1);
+ res = mp_init_set_int(&_mx, 1uL);
if (res != MP_OKAY) {
goto end;
}
@@ -33,7 +33,7 @@ int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
goto end;
}
- if (as) {
+ if (as != MP_NO) {
res = mp_init(&acpy);
if (res != MP_OKAY) {
goto end;
@@ -46,7 +46,7 @@ int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
}
a = &acpy;
}
- if (bs) {
+ if (bs != MP_NO) {
res = mp_init(&bcpy);
if (res != MP_OKAY) {
goto end;
@@ -62,9 +62,8 @@ int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
}
res = mp_and(a, b, c);
- s = as & bs;
- if (s && res == MP_OKAY) {
+ if ((as != MP_NO) && (bs != MP_NO) && (res == MP_OKAY)) {
res = mp_sub(c, mx, c);
}
diff --git a/bn_mp_tc_div_2d.c b/bn_mp_tc_div_2d.c
index 5ea4e38..3c617ef 100644
--- a/bn_mp_tc_div_2d.c
+++ b/bn_mp_tc_div_2d.c
@@ -17,17 +17,17 @@
int mp_tc_div_2d(const mp_int *a, int b, mp_int *c)
{
int res;
- if (!mp_isneg(a)) {
- return mp_div_2d(a, b, c, 0);
+ if (mp_isneg(a) == MP_NO) {
+ return mp_div_2d(a, b, c, NULL);
}
- res = mp_add_d(a, 1, c);
+ res = mp_add_d(a, 1uL, c);
if (res != MP_OKAY) {
return res;
}
- res = mp_div_2d(c, b, c, 0);
- return res == MP_OKAY ? mp_sub_d(c, 1, c) : res;
+ res = mp_div_2d(c, b, c, NULL);
+ return (res == MP_OKAY) ? mp_sub_d(c, 1uL, c) : res;
}
#endif
diff --git a/bn_mp_tc_or.c b/bn_mp_tc_or.c
index 1e7d583..91b6b40 100644
--- a/bn_mp_tc_or.c
+++ b/bn_mp_tc_or.c
@@ -17,12 +17,12 @@
int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c)
{
int res = MP_OKAY, bits;
- int as = mp_isneg(a), bs = mp_isneg(b), s = 0;
- mp_int *mx = 0, _mx, acpy, bcpy;
+ int as = mp_isneg(a), bs = mp_isneg(b);
+ mp_int *mx = NULL, _mx, acpy, bcpy;
- if (as || bs) {
+ if ((as != MP_NO) || (bs != MP_NO)) {
bits = MAX(mp_count_bits(a), mp_count_bits(b));
- res = mp_init_set_int(&_mx, 1);
+ res = mp_init_set_int(&_mx, 1uL);
if (res != MP_OKAY) {
goto end;
}
@@ -33,7 +33,7 @@ int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c)
goto end;
}
- if (as) {
+ if (as != MP_NO) {
res = mp_init(&acpy);
if (res != MP_OKAY) {
goto end;
@@ -46,7 +46,7 @@ int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c)
}
a = &acpy;
}
- if (bs) {
+ if (bs != MP_NO) {
res = mp_init(&bcpy);
if (res != MP_OKAY) {
goto end;
@@ -62,9 +62,8 @@ int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c)
}
res = mp_or(a, b, c);
- s = as | bs;
- if (s && res == MP_OKAY) {
+ if (((as != MP_NO) || (bs != MP_NO)) && (res == MP_OKAY)) {
res = mp_sub(c, mx, c);
}
diff --git a/bn_mp_tc_xor.c b/bn_mp_tc_xor.c
index be9b9d8..50fb12d 100644
--- a/bn_mp_tc_xor.c
+++ b/bn_mp_tc_xor.c
@@ -17,12 +17,12 @@
int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
{
int res = MP_OKAY, bits;
- int as = mp_isneg(a), bs = mp_isneg(b), s = 0;
- mp_int *mx = 0, _mx, acpy, bcpy;
+ int as = mp_isneg(a), bs = mp_isneg(b);
+ mp_int *mx = NULL, _mx, acpy, bcpy;
- if (as || bs) {
+ if ((as != MP_NO) || (bs != MP_NO)) {
bits = MAX(mp_count_bits(a), mp_count_bits(b));
- res = mp_init_set_int(&_mx, 1);
+ res = mp_init_set_int(&_mx, 1uL);
if (res != MP_OKAY) {
goto end;
}
@@ -33,7 +33,7 @@ int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
goto end;
}
- if (as) {
+ if (as != MP_NO) {
res = mp_init(&acpy);
if (res != MP_OKAY) {
goto end;
@@ -46,7 +46,7 @@ int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
}
a = &acpy;
}
- if (bs) {
+ if (bs != MP_NO) {
res = mp_init(&bcpy);
if (res != MP_OKAY) {
goto end;
@@ -62,9 +62,8 @@ int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
}
res = mp_xor(a, b, c);
- s = as ^ bs;
- if (s && res == MP_OKAY) {
+ if ((as != bs) && (res == MP_OKAY)) {
res = mp_sub(c, mx, c);
}