Skip to content

Commit b4c4257

Browse files
authored
Merge pull request #436 from fperrad/20191029_lint
some linting
2 parents 3035e22 + 4034280 commit b4c4257

File tree

4 files changed

+56
-56
lines changed

4 files changed

+56
-56
lines changed

demo/mtest_opponent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ static int mtest_opponent(void)
304304
DO(mp_read_radix(&c, buf, 64));
305305
DO(mp_invmod(&a, &b, &d));
306306
DO(mp_mulmod(&d, &a, &b, &e));
307-
if (mp_cmp_d(&e, 1uL) != MP_EQ) {
307+
if (mp_cmp_d(&e, 1u) != MP_EQ) {
308308
printf("inv [wrong value from MPI?!] failure\n");
309309
draw(&a);
310310
draw(&b);

demo/test.c

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ static int64_t rand_int64(void)
4343

4444
static uint32_t uabs32(int32_t x)
4545
{
46-
return x > 0 ? (uint32_t)x : -(uint32_t)x;
46+
return (x > 0) ? (uint32_t)x : -(uint32_t)x;
4747
}
4848

4949
static uint64_t uabs64(int64_t x)
5050
{
51-
return x > 0 ? (uint64_t)x : -(uint64_t)x;
51+
return (x > 0) ? (uint64_t)x : -(uint64_t)x;
5252
}
5353

5454
/* This function prototype is needed
@@ -115,20 +115,20 @@ static int test_trivial_stuff(void)
115115
DO(mp_abs(&a, &b));
116116
EXPECT(!mp_isneg(&b));
117117
/* a: -5-> b: -4 */
118-
DO(mp_add_d(&a, 1uL, &b));
118+
DO(mp_add_d(&a, 1u, &b));
119119
EXPECT(mp_isneg(&b));
120120
EXPECT(mp_get_i32(&b) == -4);
121121
EXPECT(mp_get_u32(&b) == (uint32_t)-4);
122122
EXPECT(mp_get_mag_u32(&b) == 4);
123123
/* a: -5-> b: 1 */
124-
DO(mp_add_d(&a, 6uL, &b));
124+
DO(mp_add_d(&a, 6u, &b));
125125
EXPECT(mp_get_u32(&b) == 1);
126126
/* a: -5-> a: 1 */
127-
DO(mp_add_d(&a, 6uL, &a));
127+
DO(mp_add_d(&a, 6u, &a));
128128
EXPECT(mp_get_u32(&a) == 1);
129129
mp_zero(&a);
130130
/* a: 0-> a: 6 */
131-
DO(mp_add_d(&a, 6uL, &a));
131+
DO(mp_add_d(&a, 6u, &a));
132132
EXPECT(mp_get_u32(&a) == 6);
133133

134134
mp_set(&a, 42u);
@@ -223,9 +223,9 @@ static int test_mp_get_set_i64(void)
223223

224224
DOR(mp_init(&a));
225225

226-
check_get_set_i64(&a, 0);
227-
check_get_set_i64(&a, -1);
228-
check_get_set_i64(&a, 1);
226+
check_get_set_i64(&a, 0LL);
227+
check_get_set_i64(&a, -1LL);
228+
check_get_set_i64(&a, 1LL);
229229
check_get_set_i64(&a, INT64_MIN);
230230
check_get_set_i64(&a, INT64_MAX);
231231

@@ -282,7 +282,7 @@ static int test_mp_rand(void)
282282
DO(mp_rand(&a, n));
283283
DO(mp_incr(&a));
284284
DO(mp_div_2d(&a, n * MP_DIGIT_BIT, &b, NULL));
285-
if (mp_cmp_d(&b, 1) != MP_EQ) {
285+
if (mp_cmp_d(&b, 1u) != MP_EQ) {
286286
ndraw(&a, "mp_rand() a");
287287
ndraw(&b, "mp_rand() b");
288288
e = MP_ERR;
@@ -292,7 +292,7 @@ static int test_mp_rand(void)
292292
LBL_ERR:
293293
mp_rand_source(s_mp_rand_jenkins);
294294
mp_clear_multi(&a, &b, NULL);
295-
return e == MP_OKAY ? EXIT_SUCCESS : EXIT_FAILURE;
295+
return (e == MP_OKAY) ? EXIT_SUCCESS : EXIT_FAILURE;
296296
}
297297

298298
static int test_mp_kronecker(void)
@@ -729,7 +729,7 @@ static int test_mp_sqrt(void)
729729
printf("\nmp_sqrt() error!");
730730
goto LBL_ERR;
731731
}
732-
DO(mp_root_u32(&a, 2uL, &c));
732+
DO(mp_root_u32(&a, 2u, &c));
733733
if (mp_cmp_mag(&b, &c) != MP_EQ) {
734734
printf("mp_sqrt() bad result!\n");
735735
goto LBL_ERR;
@@ -770,7 +770,7 @@ static int test_mp_is_square(void)
770770
}
771771

772772
/* test for false positives */
773-
DO(mp_add_d(&a, 1uL, &a));
773+
DO(mp_add_d(&a, 1u, &a));
774774
if (mp_is_square(&a, &res) != MP_OKAY) {
775775
printf("\nfp:mp_is_square() error!");
776776
goto LBL_ERR;
@@ -879,9 +879,9 @@ static int test_mp_prime_is_prime(void)
879879
}
880880
/* About the same size as Arnault's pseudoprime */
881881
printf("\rTesting mp_prime_is_prime() with certified prime 2^1119 + 53 ");
882-
mp_set(&a, 1uL);
882+
mp_set(&a, 1u);
883883
DO(mp_mul_2d(&a,1119,&a));
884-
DO(mp_add_d(&a, 53uL, &a));
884+
DO(mp_add_d(&a, 53u, &a));
885885
e = mp_prime_is_prime(&a, mp_prime_rabin_miller_trials(mp_count_bits(&a)), &cnt);
886886
/* small problem */
887887
if (e != MP_OKAY) {
@@ -912,7 +912,7 @@ static int test_mp_prime_is_prime(void)
912912
goto LBL_ERR;
913913
}
914914
/* let's see if it's really a safe prime */
915-
DO(mp_sub_d(&a, 1uL, &b));
915+
DO(mp_sub_d(&a, 1u, &b));
916916
DO(mp_div_2(&b, &b));
917917
e = mp_prime_is_prime(&b, mp_prime_rabin_miller_trials(mp_count_bits(&b)), &cnt);
918918
/* small problem */
@@ -1010,7 +1010,7 @@ static int test_mp_prime_next_prime(void)
10101010
putchar('\n');
10111011
goto LBL_ERR;
10121012
}
1013-
mp_set(&a, 8);
1013+
mp_set(&a, 8u);
10141014
DO(mp_prime_next_prime(&a, 5, true));
10151015
if (mp_cmp_d(&a, 11u) != MP_EQ) {
10161016
printf("mp_prime_next_prime: output should have been 11 but was: ");
@@ -1092,7 +1092,7 @@ static int test_mp_montgomery_reduce(void)
10921092

10931093
/* now test a random reduction */
10941094
for (ix = 0; ix < 100; ix++) {
1095-
DO(mp_rand(&c, 1 + abs(rand_int()) % (2*i)));
1095+
DO(mp_rand(&c, 1 + (abs(rand_int()) % (2*i))));
10961096
DO(mp_copy(&c, &d));
10971097
DO(mp_copy(&c, &e));
10981098

@@ -1183,7 +1183,7 @@ static int test_mp_cnt_lsb(void)
11831183
mp_int a, b;
11841184
DOR(mp_init_multi(&a, &b, NULL));
11851185

1186-
mp_set(&a, 1uL);
1186+
mp_set(&a, 1u);
11871187
for (ix = 0; ix < 1024; ix++) {
11881188
if (mp_cnt_lsb(&a) != ix) {
11891189
printf("Failed at %d, %d\n", ix, mp_cnt_lsb(&a));
@@ -1212,7 +1212,7 @@ static int test_mp_reduce_2k(void)
12121212
mp_digit tmp;
12131213

12141214
DO(mp_2expt(&a, cnt));
1215-
DO(mp_sub_d(&a, 2uL, &a)); /* a = 2**cnt - 2 */
1215+
DO(mp_sub_d(&a, 2u, &a)); /* a = 2**cnt - 2 */
12161216

12171217
printf("\r %4d bits", cnt);
12181218
printf("(%d)", mp_reduce_is_2k(&a));
@@ -1223,10 +1223,10 @@ static int test_mp_reduce_2k(void)
12231223
printf(".");
12241224
fflush(stdout);
12251225
}
1226-
DO(mp_rand(&b, (cnt / MP_DIGIT_BIT + 1) * 2));
1226+
DO(mp_rand(&b, ((cnt / MP_DIGIT_BIT) + 1) * 2));
12271227
DO(mp_copy(&c, &b));
12281228
DO(mp_mod(&c, &a, &c));
1229-
DO(mp_reduce_2k(&b, &a, 2uL));
1229+
DO(mp_reduce_2k(&b, &a, 2u));
12301230
if (mp_cmp(&c, &b) != MP_EQ) {
12311231
printf("FAILED\n");
12321232
goto LBL_ERR;
@@ -1249,15 +1249,15 @@ static int test_mp_div_3(void)
12491249
DOR(mp_init_multi(&a, &b, &c, &d, &e, NULL));
12501250

12511251
/* test mp_div_3 */
1252-
mp_set(&d, 3uL);
1252+
mp_set(&d, 3u);
12531253
for (cnt = 0; cnt < 10000;) {
12541254
mp_digit r2;
12551255

12561256
if (!(++cnt & 127)) {
12571257
printf("\r %9d", cnt);
12581258
fflush(stdout);
12591259
}
1260-
DO(mp_rand(&a, abs(rand_int()) % 128 + 1));
1260+
DO(mp_rand(&a, (abs(rand_int()) % 128) + 1));
12611261
DO(mp_div(&a, &d, &b, &e));
12621262
DO(mp_div_3(&a, &c, &r2));
12631263

@@ -1306,7 +1306,7 @@ static int test_mp_dr_reduce(void)
13061306
fflush(stdout);
13071307
}
13081308
DO(mp_sqr(&b, &b));
1309-
DO(mp_add_d(&b, 1uL, &b));
1309+
DO(mp_add_d(&b, 1u, &b));
13101310
DO(mp_copy(&b, &c));
13111311

13121312
DO(mp_mod(&b, &a, &b));
@@ -1370,10 +1370,10 @@ static int test_mp_reduce_2k_l(void)
13701370
fflush(stdout);
13711371
for (cnt = 0; cnt < (int)(1uL << 20); cnt++) {
13721372
DO(mp_sqr(&b, &b));
1373-
DO(mp_add_d(&b, 1uL, &b));
1373+
DO(mp_add_d(&b, 1u, &b));
13741374
DO(mp_reduce_2k_l(&b, &a, &d));
13751375
DO(mp_sqr(&c, &c));
1376-
DO(mp_add_d(&c, 1uL, &c));
1376+
DO(mp_add_d(&c, 1u, &c));
13771377
DO(mp_mod(&c, &a, &c));
13781378
if (mp_cmp(&b, &c) != MP_EQ) {
13791379
printf("mp_reduce_2k_l() failed at step %d\n", cnt);
@@ -1439,7 +1439,7 @@ static int test_mp_log_u32(void)
14391439
0 x MP_VAL
14401440
1 x MP_VAL
14411441
*/
1442-
mp_set(&a, 42uL);
1442+
mp_set(&a, 42u);
14431443
base = 0u;
14441444
if (mp_log_u32(&a, base, &lb) != MP_VAL) {
14451445
goto LBL_ERR;
@@ -1520,8 +1520,8 @@ static int test_mp_log_u32(void)
15201520

15211521
/*Test upper edgecase with base UINT32_MAX and number (UINT32_MAX/2)*UINT32_MAX^10 */
15221522
mp_set(&a, max_base);
1523-
DO(mp_expt_u32(&a, 10uL, &a));
1524-
DO(mp_add_d(&a, max_base / 2, &a));
1523+
DO(mp_expt_u32(&a, 10u, &a));
1524+
DO(mp_add_d(&a, max_base / 2u, &a));
15251525
DO(mp_log_u32(&a, max_base, &lb));
15261526
if (lb != 10u) {
15271527
goto LBL_ERR;
@@ -1543,30 +1543,30 @@ static int test_mp_incr(void)
15431543
/* Does it increment inside the limits of a MP_xBIT limb? */
15441544
mp_set(&a, MP_MASK/2);
15451545
DO(mp_incr(&a));
1546-
if (mp_cmp_d(&a, (MP_MASK/2uL) + 1uL) != MP_EQ) {
1546+
if (mp_cmp_d(&a, (MP_MASK/2u) + 1u) != MP_EQ) {
15471547
goto LBL_ERR;
15481548
}
15491549

15501550
/* Does it increment outside of the limits of a MP_xBIT limb? */
15511551
mp_set(&a, MP_MASK);
15521552
mp_set(&b, MP_MASK);
15531553
DO(mp_incr(&a));
1554-
DO(mp_add_d(&b, 1uL, &b));
1554+
DO(mp_add_d(&b, 1u, &b));
15551555
if (mp_cmp(&a, &b) != MP_EQ) {
15561556
goto LBL_ERR;
15571557
}
15581558

15591559
/* Does it increment from -1 to 0? */
1560-
mp_set(&a, 1uL);
1560+
mp_set(&a, 1u);
15611561
a.sign = MP_NEG;
15621562
DO(mp_incr(&a));
1563-
if (mp_cmp_d(&a, 0uL) != MP_EQ) {
1563+
if (mp_cmp_d(&a, 0u) != MP_EQ) {
15641564
goto LBL_ERR;
15651565
}
15661566

15671567
/* Does it increment from -(MP_MASK + 1) to -MP_MASK? */
15681568
mp_set(&a, MP_MASK);
1569-
DO(mp_add_d(&a, 1uL, &a));
1569+
DO(mp_add_d(&a, 1u, &a));
15701570
a.sign = MP_NEG;
15711571
DO(mp_incr(&a));
15721572
if (a.sign != MP_NEG) {
@@ -1593,13 +1593,13 @@ static int test_mp_decr(void)
15931593
/* Does it decrement inside the limits of a MP_xBIT limb? */
15941594
mp_set(&a, MP_MASK/2);
15951595
DO(mp_decr(&a));
1596-
if (mp_cmp_d(&a, (MP_MASK/2uL) - 1uL) != MP_EQ) {
1596+
if (mp_cmp_d(&a, (MP_MASK/2u) - 1u) != MP_EQ) {
15971597
goto LBL_ERR;
15981598
}
15991599

16001600
/* Does it decrement outside of the limits of a MP_xBIT limb? */
16011601
mp_set(&a, MP_MASK);
1602-
DO(mp_add_d(&a, 1uL, &a));
1602+
DO(mp_add_d(&a, 1u, &a));
16031603
DO(mp_decr(&a));
16041604
if (mp_cmp_d(&a, MP_MASK) != MP_EQ) {
16051605
goto LBL_ERR;
@@ -1610,7 +1610,7 @@ static int test_mp_decr(void)
16101610
DO(mp_decr(&a));
16111611
if (a.sign == MP_NEG) {
16121612
a.sign = MP_ZPOS;
1613-
if (mp_cmp_d(&a, 1uL) != MP_EQ) {
1613+
if (mp_cmp_d(&a, 1u) != MP_EQ) {
16141614
goto LBL_ERR;
16151615
}
16161616
} else {
@@ -1623,7 +1623,7 @@ static int test_mp_decr(void)
16231623
a.sign = MP_NEG;
16241624
mp_set(&b, MP_MASK);
16251625
b.sign = MP_NEG;
1626-
DO(mp_sub_d(&b, 1uL, &b));
1626+
DO(mp_sub_d(&b, 1u, &b));
16271627
DO(mp_decr(&a));
16281628
if (mp_cmp(&a, &b) != MP_EQ) {
16291629
goto LBL_ERR;
@@ -1903,7 +1903,7 @@ static int test_s_mp_mul_karatsuba(void)
19031903
int size;
19041904

19051905
DOR(mp_init_multi(&a, &b, &c, &d, NULL));
1906-
for (size = MP_MUL_KARATSUBA_CUTOFF; size < MP_MUL_KARATSUBA_CUTOFF + 20; size++) {
1906+
for (size = MP_MUL_KARATSUBA_CUTOFF; size < (MP_MUL_KARATSUBA_CUTOFF + 20); size++) {
19071907
DO(mp_rand(&a, size));
19081908
DO(mp_rand(&b, size));
19091909
DO(s_mp_mul_karatsuba(&a, &b, &c));
@@ -1927,7 +1927,7 @@ static int test_s_mp_sqr_karatsuba(void)
19271927
int size;
19281928

19291929
DOR(mp_init_multi(&a, &b, &c, NULL));
1930-
for (size = MP_SQR_KARATSUBA_CUTOFF; size < MP_SQR_KARATSUBA_CUTOFF + 20; size++) {
1930+
for (size = MP_SQR_KARATSUBA_CUTOFF; size < (MP_SQR_KARATSUBA_CUTOFF + 20); size++) {
19311931
DO(mp_rand(&a, size));
19321932
DO(s_mp_sqr_karatsuba(&a, &b));
19331933
DO(s_mp_sqr(&a, &c));
@@ -1976,7 +1976,7 @@ static int test_s_mp_mul_toom(void)
19761976
}
19771977
#endif
19781978

1979-
for (size = MP_MUL_TOOM_CUTOFF; size < MP_MUL_TOOM_CUTOFF + 20; size++) {
1979+
for (size = MP_MUL_TOOM_CUTOFF; size < (MP_MUL_TOOM_CUTOFF + 20); size++) {
19801980
DO(mp_rand(&a, size));
19811981
DO(mp_rand(&b, size));
19821982
DO(s_mp_mul_toom(&a, &b, &c));
@@ -2000,7 +2000,7 @@ static int test_s_mp_sqr_toom(void)
20002000
int size;
20012001

20022002
DOR(mp_init_multi(&a, &b, &c, NULL));
2003-
for (size = MP_SQR_TOOM_CUTOFF; size < MP_SQR_TOOM_CUTOFF + 20; size++) {
2003+
for (size = MP_SQR_TOOM_CUTOFF; size < (MP_SQR_TOOM_CUTOFF + 20); size++) {
20042004
DO(mp_rand(&a, size));
20052005
DO(s_mp_sqr_toom(&a, &b));
20062006
DO(s_mp_sqr(&a, &c));
@@ -2038,7 +2038,7 @@ static int test_mp_radix_size(void)
20382038
DOR(mp_init(&a));
20392039

20402040
/* number to result in a different size for every base: 67^(4 * 67) */
2041-
mp_set(&a, 67);
2041+
mp_set(&a, 67u);
20422042
DO(mp_expt_u32(&a, 268u, &a));
20432043

20442044
for (radix = 2; radix < 65; radix++) {
@@ -2075,7 +2075,7 @@ static int test_s_mp_div_recursive(void)
20752075

20762076
DOR(mp_init_multi(&a, &b, &c_q, &c_r, &d_q, &d_r, NULL));
20772077

2078-
for (size = MP_MUL_KARATSUBA_CUTOFF; size < 3 * MP_MUL_KARATSUBA_CUTOFF; size += 10) {
2078+
for (size = MP_MUL_KARATSUBA_CUTOFF; size < (3 * MP_MUL_KARATSUBA_CUTOFF); size += 10) {
20792079
printf("\rsizes = %d / %d", 10 * size, size);
20802080
/* Relation 10:1 */
20812081
DO(mp_rand(&a, 10 * size));
@@ -2254,18 +2254,18 @@ static int test_mp_pack_unpack(void)
22542254
DOR(mp_init_multi(&a, &b, NULL));
22552255
DO(mp_rand(&a, 15));
22562256

2257-
count = mp_pack_count(&a, 0, 1);
2257+
count = mp_pack_count(&a, 0uL, 1uL);
22582258

22592259
buf = malloc(count);
22602260
if (buf == NULL) {
22612261
fprintf(stderr, "test_pack_unpack failed to allocate\n");
22622262
goto LBL_ERR;
22632263
}
22642264

2265-
DO(mp_pack((void *)buf, count, &written, order, 1,
2266-
endianess, 0, &a));
2267-
DO(mp_unpack(&b, count, order, 1,
2268-
endianess, 0, (const void *)buf));
2265+
DO(mp_pack((void *)buf, count, &written, order, 1uL,
2266+
endianess, 0uL, &a));
2267+
DO(mp_unpack(&b, count, order, 1uL,
2268+
endianess, 0uL, (const void *)buf));
22692269

22702270
if (mp_cmp(&a, &b) != MP_EQ) {
22712271
fprintf(stderr, "pack/unpack cycle failed\n");
@@ -2289,7 +2289,7 @@ static int unit_tests(int argc, char **argv)
22892289
} test[] = {
22902290
#define T0(n) { #n, test_##n }
22912291
#define T1(n, o) { #n, MP_HAS(o) ? test_##n : NULL }
2292-
#define T2(n, o1, o2) { #n, MP_HAS(o1) && MP_HAS(o2) ? test_##n : NULL }
2292+
#define T2(n, o1, o2) { #n, (MP_HAS(o1) && MP_HAS(o2)) ? test_##n : NULL }
22932293
T0(feature_detection),
22942294
T0(trivial_stuff),
22952295
T2(mp_get_set_i32, MP_GET_I32, MP_GET_MAG_U32),
@@ -2351,7 +2351,7 @@ static int unit_tests(int argc, char **argv)
23512351
s_mp_rand_jenkins_init(t);
23522352
mp_rand_source(s_mp_rand_jenkins);
23532353

2354-
for (i = 0; i < sizeof(test) / sizeof(test[0]); ++i) {
2354+
for (i = 0; i < (sizeof(test) / sizeof(test[0])); ++i) {
23552355
if (argc > 1) {
23562356
for (j = 1; j < argc; ++j) {
23572357
if (strstr(test[i].name, argv[j]) != NULL) {

0 commit comments

Comments
 (0)