mtest: fix compiler warnings
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
diff --git a/mtest/mpi.c b/mtest/mpi.c
index d475c5e..48dbe27 100644
--- a/mtest/mpi.c
+++ b/mtest/mpi.c
@@ -1264,7 +1264,7 @@ mp_err mp_expt(mp_int *a, mp_int *b, mp_int *c)
mp_int s, x;
mp_err res;
mp_digit d;
- int dig, bit;
+ unsigned int bit, dig;
ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG);
@@ -1637,7 +1637,7 @@ mp_err mp_exptmod(mp_int *a, mp_int *b, mp_int *m, mp_int *c)
mp_err res;
mp_digit d, *db = DIGITS(b);
mp_size ub = USED(b);
- int dig, bit;
+ unsigned int bit, dig;
ARGCHK(a != NULL && b != NULL && c != NULL, MP_BADARG);
@@ -2387,7 +2387,7 @@ mp_err mp_to_unsigned_bin(mp_int *mp, unsigned char *str)
/* Generate digits in reverse order */
while(dp < end) {
- int ix;
+ unsigned int ix;
d = *dp;
for(ix = 0; ix < sizeof(mp_digit); ++ix) {
@@ -2541,7 +2541,7 @@ int mp_value_radix_size(int num, int qty, int radix)
/* {{{ mp_toradix(mp, str, radix) */
-mp_err mp_toradix(mp_int *mp, unsigned char *str, int radix)
+mp_err mp_toradix(mp_int *mp, char *str, int radix)
{
int ix, pos = 0;
@@ -2587,10 +2587,10 @@ mp_err mp_toradix(mp_int *mp, unsigned char *str, int radix)
/* Reverse the digits and sign indicator */
ix = 0;
while(ix < pos) {
- char tmp = str[ix];
+ char _tmp = str[ix];
str[ix] = str[pos];
- str[pos] = tmp;
+ str[pos] = _tmp;
++ix;
--pos;
}
@@ -2833,7 +2833,7 @@ mp_err s_mp_lshd(mp_int *mp, mp_size p)
dp[ix + p] = dp[ix];
/* Fill the bottom digits with zeroes */
- for(ix = 0; ix < p; ix++)
+ for(ix = 0; (unsigned)ix < p; ix++)
dp[ix] = 0;
return MP_OKAY;
@@ -2898,7 +2898,7 @@ void s_mp_div_2(mp_int *mp)
mp_err s_mp_mul_2(mp_int *mp)
{
- int ix;
+ unsigned int ix;
mp_digit kin = 0, kout, *dp = DIGITS(mp);
mp_err res;
@@ -2970,7 +2970,7 @@ mp_err s_mp_mul_2d(mp_int *mp, mp_digit d)
mp_err res;
mp_digit save, next, mask, *dp;
mp_size used;
- int ix;
+ unsigned int ix;
if((res = s_mp_lshd(mp, d / DIGIT_BIT)) != MP_OKAY)
return res;
diff --git a/mtest/mpi.h b/mtest/mpi.h
index 559f172..5accb52 100644
--- a/mtest/mpi.h
+++ b/mtest/mpi.h
@@ -210,7 +210,7 @@ int mp_count_bits(mp_int *mp);
mp_err mp_read_radix(mp_int *mp, unsigned char *str, int radix);
int mp_radix_size(mp_int *mp, int radix);
int mp_value_radix_size(int num, int qty, int radix);
-mp_err mp_toradix(mp_int *mp, unsigned char *str, int radix);
+mp_err mp_toradix(mp_int *mp, char *str, int radix);
int mp_char2value(char ch, int r);
diff --git a/mtest/mtest.c b/mtest/mtest.c
index 6ac2c81..a520643 100644
--- a/mtest/mtest.c
+++ b/mtest/mtest.c
@@ -43,24 +43,32 @@ FILE *rng;
void rand_num(mp_int *a)
{
- int n, size;
+ int size;
unsigned char buf[2048];
+ size_t sz;
size = 1 + ((fgetc(rng)<<8) + fgetc(rng)) % 101;
buf[0] = (fgetc(rng)&1)?1:0;
- fread(buf+1, 1, size, rng);
+ sz = fread(buf+1, 1, size, rng);
+ if (sz != (unsigned)size) {
+ fprintf(stderr, "\nWarning: fread failed\n\n");
+ }
while (buf[1] == 0) buf[1] = fgetc(rng);
mp_read_raw(a, buf, 1+size);
}
void rand_num2(mp_int *a)
{
- int n, size;
+ int size;
unsigned char buf[2048];
+ size_t sz;
size = 10 + ((fgetc(rng)<<8) + fgetc(rng)) % 101;
buf[0] = (fgetc(rng)&1)?1:0;
- fread(buf+1, 1, size, rng);
+ sz = fread(buf+1, 1, size, rng);
+ if (sz != (unsigned)size) {
+ fprintf(stderr, "\nWarning: fread failed\n\n");
+ }
while (buf[1] == 0) buf[1] = fgetc(rng);
mp_read_raw(a, buf, 1+size);
}