Commit 9f2cd0430101f7f85a857a05ca9e34c3ca36029b

Jan Nijtmans 2019-11-12T15:30:34

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

diff --git a/demo/test.c b/demo/test.c
index f42c630..66a6f07 100644
--- a/demo/test.c
+++ b/demo/test.c
@@ -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;
diff --git a/demo/timing.c b/demo/timing.c
index 76ca01f..a66ce85 100644
--- a/demo/timing.c
+++ b/demo/timing.c
@@ -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;
diff --git a/s_mp_rand_jenkins.c b/s_mp_rand_jenkins.c
index 4bb520c..6aba0fb 100644
--- a/s_mp_rand_jenkins.c
+++ b/s_mp_rand_jenkins.c
@@ -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;
       }
    }