Commit 3a744dc46d3b9afd265c4a3a1f444f01a08772c0

Daniel Mendler 2019-12-05T00:33:53

s_mp_radix_size_overestimate: remove overflow check

diff --git a/mp_grow.c b/mp_grow.c
index 0de6679..344a5a8 100644
--- a/mp_grow.c
+++ b/mp_grow.c
@@ -8,6 +8,7 @@ mp_err mp_grow(mp_int *a, int size)
 {
    /* if the alloc size is smaller alloc more ram */
    if (a->alloc < size) {
+           /* TODO */
       /* reallocate the array a->dp
        *
        * We store the return in a temporary variable
diff --git a/mp_init_size.c b/mp_init_size.c
index 9aa98b9..fb7a37d 100644
--- a/mp_init_size.c
+++ b/mp_init_size.c
@@ -8,6 +8,7 @@ mp_err mp_init_size(mp_int *a, int size)
 {
    size = MP_MAX(MP_MIN_PREC, size);
 
+   /*TODO*/
    /* alloc mem */
    a->dp = (mp_digit *) MP_CALLOC((size_t)size, sizeof(mp_digit));
    if (a->dp == NULL) {
diff --git a/s_mp_radix_size_overestimate.c b/s_mp_radix_size_overestimate.c
index 35dd1e6..4f05997 100644
--- a/s_mp_radix_size_overestimate.c
+++ b/s_mp_radix_size_overestimate.c
@@ -52,12 +52,7 @@ mp_err s_mp_radix_size_overestimate(const mp_int *a, const int radix, size_t *si
 
    if (MP_HAS(S_MP_LOG_2EXPT) && MP_IS_2EXPT((mp_digit)radix)) {
       /* floor(log_{2^n}(a)) + 1 + EOS + sign */
-      *size = (size_t)(s_mp_log_2expt(a, (mp_digit)radix));
-      /* Would overflow with base 2 otherwise */
-      if (*size > (INT_MAX - 4)) {
-         return MP_VAL;
-      }
-      *size += 3u;
+      *size = (size_t)(s_mp_log_2expt(a, (mp_digit)radix) + 3);
       return MP_OKAY;
    }