Skip to content

Commit 32b3351

Browse files
authored
Merge pull request #200 from libtom/cast-cleanup
remove unnecessary size_t casts, fix Wconversion/Wsign-conversion issues
2 parents c113118 + 5da4e0a commit 32b3351

18 files changed

+24
-22
lines changed

bn_mp_get_long.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ unsigned long mp_get_long(const mp_int *a)
2323
}
2424

2525
/* get number of digits of the lsb we have to read */
26-
i = MIN(a->used, ((((int)sizeof(unsigned long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
26+
i = MIN(a->used, (((CHAR_BIT * (int)sizeof(unsigned long)) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
2727

2828
/* get most significant digit of result */
2929
res = (unsigned long)a->dp[i];

bn_mp_get_long_long.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ unsigned long long mp_get_long_long(const mp_int *a)
2323
}
2424

2525
/* get number of digits of the lsb we have to read */
26-
i = MIN(a->used, ((((int)sizeof(unsigned long long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
26+
i = MIN(a->used, (((CHAR_BIT * (int)sizeof(unsigned long long)) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1;
2727

2828
/* get most significant digit of result */
2929
res = (unsigned long long)a->dp[i];

bn_mp_grow.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ int mp_grow(mp_int *a, int size)
2929
* in case the operation failed we don't want
3030
* to overwrite the dp member of a.
3131
*/
32-
tmp = (mp_digit *) XREALLOC(a->dp, sizeof(mp_digit) * (size_t)size);
32+
tmp = (mp_digit *) XREALLOC(a->dp, (size_t)size * sizeof(mp_digit));
3333
if (tmp == NULL) {
3434
/* reallocation failed but "a" is still valid [can be freed] */
3535
return MP_MEM;

bn_mp_init.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ int mp_init(mp_int *a)
1818
int i;
1919

2020
/* allocate memory required and clear it */
21-
a->dp = (mp_digit *) XMALLOC(sizeof(mp_digit) * (size_t)MP_PREC);
21+
a->dp = (mp_digit *) XMALLOC(MP_PREC * sizeof(mp_digit));
2222
if (a->dp == NULL) {
2323
return MP_MEM;
2424
}

bn_mp_init_size.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ int mp_init_size(mp_int *a, int size)
2121
size += (MP_PREC * 2) - (size % MP_PREC);
2222

2323
/* alloc mem */
24-
a->dp = (mp_digit *) XMALLOC(sizeof(mp_digit) * (size_t)size);
24+
a->dp = (mp_digit *) XMALLOC((size_t)size * sizeof(mp_digit));
2525
if (a->dp == NULL) {
2626
return MP_MEM;
2727
}

bn_mp_montgomery_reduce.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho)
2828
if ((digs < (int)MP_WARRAY) &&
2929
(x->used <= (int)MP_WARRAY) &&
3030
(n->used <
31-
(int)(1u << (((size_t)CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT))))) {
31+
(int)(1u << ((CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT))))) {
3232
return fast_mp_montgomery_reduce(x, n, rho);
3333
}
3434

bn_mp_mul.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ int mp_mul(const mp_int *a, const mp_int *b, mp_int *c)
4242
#ifdef BN_FAST_S_MP_MUL_DIGS_C
4343
if ((digs < (int)MP_WARRAY) &&
4444
(MIN(a->used, b->used) <=
45-
(int)(1u << (((size_t)CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT))))) {
45+
(int)(1u << ((CHAR_BIT * sizeof(mp_word)) - (2u * (size_t)DIGIT_BIT))))) {
4646
res = fast_s_mp_mul_digs(a, b, c, digs);
4747
} else
4848
#endif

bn_mp_prime_is_prime.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ int mp_prime_is_prime(const mp_int *a, int t, int *result)
300300
if ((err = mp_rand(&b, 1)) != MP_OKAY) {
301301
goto LBL_B;
302302
}
303-
fips_rand <<= sizeof(mp_digit) * CHAR_BIT;
303+
fips_rand <<= CHAR_BIT * sizeof(mp_digit);
304304
fips_rand |= (unsigned int) b.dp[0];
305305
fips_rand &= mask;
306306
}

bn_mp_prime_random_ex.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
5252
}
5353

5454
/* calc the maskAND value for the MSbyte*/
55-
maskAND = ((size&7) == 0) ? 0xFF : (0xFF >> (8 - (size & 7)));
55+
maskAND = ((size&7) == 0) ? 0xFF : (unsigned char)(0xFF >> (8 - (size & 7)));
5656

5757
/* calc the maskOR_msb */
5858
maskOR_msb = 0;
5959
maskOR_msb_offset = ((size & 7) == 1) ? 1 : 0;
6060
if ((flags & LTM_PRIME_2MSB_ON) != 0) {
61-
maskOR_msb |= 0x80 >> ((9 - size) & 7);
61+
maskOR_msb |= (unsigned char)(0x80 >> ((9 - size) & 7));
6262
}
6363

6464
/* get the maskOR_lsb */
@@ -76,7 +76,7 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
7676

7777
/* work over the MSbyte */
7878
tmp[0] &= maskAND;
79-
tmp[0] |= 1 << ((size - 1) & 7);
79+
tmp[0] |= (unsigned char)(1 << ((size - 1) & 7));
8080

8181
/* mix in the maskORs */
8282
tmp[maskOR_msb_offset] |= maskOR_msb;

bn_mp_rand.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ static int s_read_win_csp(mp_digit *p)
8686

8787
static int s_read_getrandom(mp_digit *p)
8888
{
89-
int ret;
89+
ssize_t ret;
9090
do {
9191
ret = getrandom(p, sizeof(*p), 0);
9292
} while ((ret == -1) && (errno == EINTR));

0 commit comments

Comments
 (0)