more unnecessary type-casts, correct type-case for malloc

This commit is contained in:
Jan Nijtmans 2019-11-12 15:30:34 +01:00 committed by Steffen Jaeckel
parent e9d54e9867
commit 9f2cd04301
No known key found for this signature in database
GPG Key ID: AF0CB17621EDAD72
3 changed files with 9 additions and 9 deletions

View File

@ -618,14 +618,14 @@ LBL_ERR:
static int test_mp_get_u32(void)
{
unsigned long t;
uint32_t t;
int i;
mp_int a, b;
DOR(mp_init_multi(&a, &b, NULL));
for (i = 0; i < 1000; ++i) {
t = (unsigned long)rand_long() & (unsigned long)UINT32_MAX;
t = (uint32_t)rand_long();
mp_set_ul(&a, t);
if (t != mp_get_u32(&a)) {
printf("\nmp_get_u32() bad result!");
@ -637,7 +637,7 @@ static int test_mp_get_u32(void)
printf("\nmp_get_u32() bad result!");
goto LBL_ERR;
}
mp_set_ul(&a, (unsigned long)UINT32_MAX);
mp_set_ul(&a, UINT32_MAX);
if (mp_get_u32(&a) != UINT32_MAX) {
printf("\nmp_get_u32() bad result!");
goto LBL_ERR;
@ -2177,7 +2177,7 @@ static int test_mp_read_write_ubin(void)
size = mp_ubin_size(&a);
printf("mp_to_ubin_size %zu - ", size);
buf = (unsigned char *)malloc(sizeof(*buf) * size);
buf = (uint8_t *)malloc(sizeof(*buf) * size);
if (buf == NULL) {
fprintf(stderr, "test_read_write_binaries (u) failed to allocate %zu bytes\n",
sizeof(*buf) * size);
@ -2215,7 +2215,7 @@ static int test_mp_read_write_sbin(void)
size = mp_sbin_size(&a);
printf("mp_to_sbin_size %zu - ", size);
buf = (unsigned char *)malloc(sizeof(*buf) * size);
buf = (uint8_t *)malloc(sizeof(*buf) * size);
if (buf == NULL) {
fprintf(stderr, "test_read_write_binaries (s) failed to allocate %zu bytes\n",
sizeof(*buf) * size);
@ -2255,7 +2255,7 @@ static int test_mp_pack_unpack(void)
count = mp_pack_count(&a, 0uL, 1uL);
buf = (unsigned char *)malloc(count);
buf = (uint8_t *)malloc(count);
if (buf == NULL) {
fprintf(stderr, "test_pack_unpack failed to allocate\n");
goto LBL_ERR;

View File

@ -47,7 +47,7 @@ static unsigned long lfsr = 0xAAAAAAAAuL;
static unsigned int lbit(void)
{
if ((lfsr & 0x80000000uL) != 0uL) {
lfsr = ((lfsr << 1) ^ 0x8000001BuL) & (unsigned long)UINT32_MAX;
lfsr = ((lfsr << 1) ^ 0x8000001BuL) & UINT32_MAX;
return 1u;
} else {
lfsr <<= 1;

View File

@ -28,7 +28,7 @@ static uint64_t s_rand_jenkins_val(void)
void s_mp_rand_jenkins_init(uint64_t seed)
{
int i;
jenkins_x.a = (uint64_t)0xF1EA5EEDuL;
jenkins_x.a = 0xF1EA5EEDuL;
jenkins_x.b = jenkins_x.c = jenkins_x.d = seed;
for (i = 0; i < 20; ++i) {
(void)s_rand_jenkins_val();
@ -42,7 +42,7 @@ mp_err s_mp_rand_jenkins(void *p, size_t n)
int i;
uint64_t x = s_rand_jenkins_val();
for (i = 0; (i < 8) && (n > 0u); ++i, --n) {
*q++ = (char)(x & (uint64_t)0xFFu);
*q++ = (char)(x & 0xFFu);
x >>= 8;
}
}