Commit 12f0abbe86486c4ea527c41d11c2c9a84eb90331

Steffen Jaeckel 2019-03-29T10:39:24

Merge pull request #177 from libtom/remove-opt-cast remove OPT_CAST

diff --git a/bn_mp_fwrite.c b/bn_mp_fwrite.c
index 9f0c3df..8f236ab 100644
--- a/bn_mp_fwrite.c
+++ b/bn_mp_fwrite.c
@@ -22,7 +22,7 @@ int mp_fwrite(const mp_int *a, int radix, FILE *stream)
       return err;
    }
 
-   buf = OPT_CAST(char) XMALLOC((size_t)len);
+   buf = (char*) XMALLOC((size_t)len);
    if (buf == NULL) {
       return MP_MEM;
    }
diff --git a/bn_mp_grow.c b/bn_mp_grow.c
index 1d92b29..fe36d3d 100644
--- a/bn_mp_grow.c
+++ b/bn_mp_grow.c
@@ -29,7 +29,7 @@ int mp_grow(mp_int *a, int size)
        * in case the operation failed we don't want
        * to overwrite the dp member of a.
        */
-      tmp = OPT_CAST(mp_digit) XREALLOC(a->dp, sizeof(mp_digit) * (size_t)size);
+      tmp = (mp_digit*) XREALLOC(a->dp, sizeof(mp_digit) * (size_t)size);
       if (tmp == NULL) {
          /* reallocation failed but "a" is still valid [can be freed] */
          return MP_MEM;
diff --git a/bn_mp_init.c b/bn_mp_init.c
index 7520089..c66c46c 100644
--- a/bn_mp_init.c
+++ b/bn_mp_init.c
@@ -18,7 +18,7 @@ int mp_init(mp_int *a)
    int i;
 
    /* allocate memory required and clear it */
-   a->dp = OPT_CAST(mp_digit) XMALLOC(sizeof(mp_digit) * (size_t)MP_PREC);
+   a->dp = (mp_digit*) XMALLOC(sizeof(mp_digit) * (size_t)MP_PREC);
    if (a->dp == NULL) {
       return MP_MEM;
    }
diff --git a/bn_mp_init_size.c b/bn_mp_init_size.c
index 9b933fb..8f5f642 100644
--- a/bn_mp_init_size.c
+++ b/bn_mp_init_size.c
@@ -21,7 +21,7 @@ int mp_init_size(mp_int *a, int size)
    size += (MP_PREC * 2) - (size % MP_PREC);
 
    /* alloc mem */
-   a->dp = OPT_CAST(mp_digit) XMALLOC(sizeof(mp_digit) * (size_t)size);
+   a->dp = (mp_digit*) XMALLOC(sizeof(mp_digit) * (size_t)size);
    if (a->dp == NULL) {
       return MP_MEM;
    }
diff --git a/bn_mp_prime_random_ex.c b/bn_mp_prime_random_ex.c
index b0b4632..5909085 100644
--- a/bn_mp_prime_random_ex.c
+++ b/bn_mp_prime_random_ex.c
@@ -46,7 +46,7 @@ int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback
    bsize = (size>>3) + ((size&7)?1:0);
 
    /* we need a buffer of bsize bytes */
-   tmp = OPT_CAST(unsigned char) XMALLOC((size_t)bsize);
+   tmp = (unsigned char*) XMALLOC((size_t)bsize);
    if (tmp == NULL) {
       return MP_MEM;
    }
diff --git a/bn_mp_shrink.c b/bn_mp_shrink.c
index ff7905f..e033fcc 100644
--- a/bn_mp_shrink.c
+++ b/bn_mp_shrink.c
@@ -23,7 +23,7 @@ int mp_shrink(mp_int *a)
    }
 
    if (a->alloc != used) {
-      if ((tmp = OPT_CAST(mp_digit) XREALLOC(a->dp, sizeof(mp_digit) * (size_t)used)) == NULL) {
+      if ((tmp = (mp_digit*) XREALLOC(a->dp, sizeof(mp_digit) * (size_t)used)) == NULL) {
          return MP_MEM;
       }
       a->dp    = tmp;
diff --git a/tommath_private.h b/tommath_private.h
index 48cf37d..26ce161 100644
--- a/tommath_private.h
+++ b/tommath_private.h
@@ -24,15 +24,6 @@
 
 #ifdef __cplusplus
 extern "C" {
-
-/* C++ compilers don't like assigning void * to mp_digit * */
-#define OPT_CAST(x) (x *)
-
-#else
-
-/* C on the other hand doesn't care */
-#define OPT_CAST(x)
-
 #endif
 
 /* define heap macros */