Commit e581d078f671fc996d920e4b33094119c9cd414f

Steffen Jaeckel 2014-10-14T13:55:35

mtest: fix compiler warnings

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);
 }