Merge pull request #141 from fperrad/20181227_lint more 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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
diff --git a/bn_mp_tc_and.c b/bn_mp_tc_and.c
index e9fe4c6..d1f1b91 100644
--- a/bn_mp_tc_and.c
+++ b/bn_mp_tc_and.c
@@ -16,12 +16,14 @@
/* two complement and */
int mp_tc_and(const mp_int *a, const mp_int *b, mp_int *c)
{
- int res = MP_OKAY, bits;
+ int res = MP_OKAY, bits, abits, bbits;
int as = mp_isneg(a), bs = mp_isneg(b);
mp_int *mx = NULL, _mx, acpy, bcpy;
if ((as != MP_NO) || (bs != MP_NO)) {
- bits = MAX(mp_count_bits(a), mp_count_bits(b));
+ abits = mp_count_bits(a);
+ bbits = mp_count_bits(b);
+ bits = MAX(abits, bbits);
res = mp_init_set_int(&_mx, 1uL);
if (res != MP_OKAY) {
goto end;
diff --git a/bn_mp_tc_or.c b/bn_mp_tc_or.c
index 91b6b40..f177c39 100644
--- a/bn_mp_tc_or.c
+++ b/bn_mp_tc_or.c
@@ -16,12 +16,14 @@
/* two complement or */
int mp_tc_or(const mp_int *a, const mp_int *b, mp_int *c)
{
- int res = MP_OKAY, bits;
+ int res = MP_OKAY, bits, abits, bbits;
int as = mp_isneg(a), bs = mp_isneg(b);
mp_int *mx = NULL, _mx, acpy, bcpy;
if ((as != MP_NO) || (bs != MP_NO)) {
- bits = MAX(mp_count_bits(a), mp_count_bits(b));
+ abits = mp_count_bits(a);
+ bbits = mp_count_bits(b);
+ bits = MAX(abits, bbits);
res = mp_init_set_int(&_mx, 1uL);
if (res != MP_OKAY) {
goto end;
diff --git a/bn_mp_tc_xor.c b/bn_mp_tc_xor.c
index 50fb12d..a2c67a2 100644
--- a/bn_mp_tc_xor.c
+++ b/bn_mp_tc_xor.c
@@ -16,12 +16,14 @@
/* two complement xor */
int mp_tc_xor(const mp_int *a, const mp_int *b, mp_int *c)
{
- int res = MP_OKAY, bits;
+ int res = MP_OKAY, bits, abits, bbits;
int as = mp_isneg(a), bs = mp_isneg(b);
mp_int *mx = NULL, _mx, acpy, bcpy;
if ((as != MP_NO) || (bs != MP_NO)) {
- bits = MAX(mp_count_bits(a), mp_count_bits(b));
+ abits = mp_count_bits(a);
+ bbits = mp_count_bits(b);
+ bits = MAX(abits, bbits);
res = mp_init_set_int(&_mx, 1uL);
if (res != MP_OKAY) {
goto end;
diff --git a/demo/demo.c b/demo/demo.c
index b0ac10c..a93ce1d 100644
--- a/demo/demo.c
+++ b/demo/demo.c
@@ -36,7 +36,7 @@ static void ndraw(mp_int *a, const char *name)
printf("0x%s\n", buf);
}
-#if LTM_DEMO_TEST_VS_MTEST
+#if LTM_DEMO_TEST_VS_MTEST != 0
static void draw(mp_int *a)
{
ndraw(a, "");
@@ -77,13 +77,13 @@ static void _panic(int l)
fprintf(stderr, "\n%d: fgets failed\n", l);
exit(EXIT_FAILURE);
}
-#endif
#define FGETS(str, size, stream) \
{ \
char *ret = fgets(str, size, stream); \
if (!ret) { _panic(__LINE__); } \
}
+#endif
static mp_int a, b, c, d, e, f;
@@ -156,8 +156,8 @@ static char buf[4096];
int main(void)
{
unsigned rr;
- int cnt, ix;
-#if LTM_DEMO_TEST_VS_MTEST
+ int ix;
+#if LTM_DEMO_TEST_VS_MTEST != 0
unsigned long expt_n, add_n, sub_n, mul_n, div_n, sqr_n, mul2d_n, div2d_n,
gcd_n, lcm_n, inv_n, div2_n, mul2_n, add_d_n, sub_d_n;
#else
@@ -165,7 +165,7 @@ int main(void)
long k, m;
unsigned long long q, r;
mp_digit mp;
- int i, n, err, should;
+ int i, n, err, should, cnt;
#endif
if (mp_init_multi(&a, &b, &c, &d, &e, &f, NULL)!= MP_OKAY)
@@ -284,7 +284,7 @@ int main(void)
printf("Failed executing mp_jacobi(%d | %lu) %s.\n", n, jacobi[cnt].n, mp_error_to_string(err));
return EXIT_FAILURE;
}
- if (err == MP_OKAY && i != jacobi[cnt].c[n + 5]) {
+ if ((err == MP_OKAY) && (i != jacobi[cnt].c[n + 5])) {
printf("Failed trivial mp_jacobi(%d | %lu) %d != %d\n", n, jacobi[cnt].n, i, jacobi[cnt].c[n + 5]);
return EXIT_FAILURE;
}
@@ -322,7 +322,7 @@ int main(void)
printf("Failed executing mp_kronecker(%ld | %ld) %s.\n", kronecker[cnt].n, m, mp_error_to_string(err));
return EXIT_FAILURE;
}
- if (err == MP_OKAY && i != kronecker[cnt].c[m + 10]) {
+ if ((err == MP_OKAY) && (i != kronecker[cnt].c[m + 10])) {
printf("Failed trivial mp_kronecker(%ld | %ld) %d != %d\n", kronecker[cnt].n, m, i, kronecker[cnt].c[m + 10]);
return EXIT_FAILURE;
}
@@ -544,7 +544,7 @@ int main(void)
}
printf("\n\nTesting: mp_get_long\n");
- for (i = 0; i < (int)(sizeof(unsigned long)*CHAR_BIT) - 1; ++i) {
+ for (i = 0; i < ((int)(sizeof(unsigned long)*CHAR_BIT) - 1); ++i) {
t = (1ULL << (i+1)) - 1;
if (!t)
t = -1;
@@ -560,11 +560,11 @@ int main(void)
return EXIT_FAILURE;
}
t <<= 1;
- } while (t);
+ } while (t != 0uL);
}
printf("\n\nTesting: mp_get_long_long\n");
- for (i = 0; i < (int)(sizeof(unsigned long long)*CHAR_BIT) - 1; ++i) {
+ for (i = 0; i < ((int)(sizeof(unsigned long long)*CHAR_BIT) - 1); ++i) {
r = (1ULL << (i+1)) - 1;
if (!r)
r = -1;
@@ -580,7 +580,7 @@ int main(void)
return EXIT_FAILURE;
}
r <<= 1;
- } while (r);
+ } while (r != 0uLL);
}
/* test mp_sqrt */
@@ -745,12 +745,12 @@ int main(void)
if (mp_cmp(&c, &d) != MP_EQ) {
/* *INDENT-OFF* */
-printf("d = e mod a, c = e MOD a\n");
-mp_todecimal(&a, buf); printf("a = %s\n", buf);
-mp_todecimal(&e, buf); printf("e = %s\n", buf);
-mp_todecimal(&d, buf); printf("d = %s\n", buf);
-mp_todecimal(&c, buf); printf("c = %s\n", buf);
-printf("compare no compare!\n"); return EXIT_FAILURE;
+ printf("d = e mod a, c = e MOD a\n");
+ mp_todecimal(&a, buf); printf("a = %s\n", buf);
+ mp_todecimal(&e, buf); printf("e = %s\n", buf);
+ mp_todecimal(&d, buf); printf("d = %s\n", buf);
+ mp_todecimal(&c, buf); printf("c = %s\n", buf);
+ printf("compare no compare!\n"); return EXIT_FAILURE;
/* *INDENT-ON* */
}
/* only one big montgomery reduction */
@@ -815,7 +815,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
mp_copy(&c, &b);
mp_mod(&c, &a, &c);
mp_reduce_2k(&b, &a, 2uL);
- if (mp_cmp(&c, &b)) {
+ if (mp_cmp(&c, &b) != MP_EQ) {
printf("FAILED\n");
return EXIT_FAILURE;
}
@@ -868,8 +868,8 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
mp_copy(&b, &c);
mp_mod(&b, &a, &b);
- mp_dr_setup(&a, &mp),
- mp_dr_reduce(&c, &a, mp);
+ mp_dr_setup(&a, &mp);
+ mp_dr_reduce(&c, &a, mp);
if (mp_cmp(&b, &c) != MP_EQ) {
printf("Failed on trial %u\n", rr);
@@ -933,7 +933,7 @@ printf("compare no compare!\n"); return EXIT_FAILURE;
#else
div2_n = mul2_n = inv_n = expt_n = lcm_n = gcd_n = add_n =
- sub_n = mul_n = div_n = sqr_n = mul2d_n = div2d_n = cnt = add_d_n = sub_d_n = 0;
+ sub_n = mul_n = div_n = sqr_n = mul2d_n = div2d_n = add_d_n = sub_d_n = 0;
/* force KARA and TOOM to enable despite cutoffs */
KARATSUBA_SQR_CUTOFF = KARATSUBA_MUL_CUTOFF = 8;
diff --git a/etc/pprime.c b/etc/pprime.c
index 213f3c5..65a6792 100644
--- a/etc/pprime.c
+++ b/etc/pprime.c
@@ -144,7 +144,7 @@ static void gen_prime(void)
} while (x == 0uL);
if (r > 31uL) {
fwrite(&r, 1uL, sizeof(mp_digit), out);
- printf("%9u\r", r);
+ printf("%9lu\r", r);
fflush(stdout);
}
if (r < 31uL) break;
@@ -336,7 +336,7 @@ top:
mp_toradix(&a, buf, 10);
printf("A == \n%s\n\n", buf);
mp_toradix(&b, buf, 10);
- printf("B == \n%s\n\nG == %d\n", buf, bases[ii]);
+ printf("B == \n%s\n\nG == %lu\n", buf, bases[ii]);
printf("----------------------------------------------------------------\n");
}