s_mp_radix_size_overestimate: remove overflow check

This commit is contained in:
Daniel Mendler 2019-12-05 00:33:53 +01:00
parent 6ac0b0c1b6
commit 3a744dc46d
No known key found for this signature in database
GPG Key ID: D88ADB2A2693CA43
3 changed files with 3 additions and 6 deletions

View File

@ -8,6 +8,7 @@ mp_err mp_grow(mp_int *a, int size)
{ {
/* if the alloc size is smaller alloc more ram */ /* if the alloc size is smaller alloc more ram */
if (a->alloc < size) { if (a->alloc < size) {
/* TODO */
/* reallocate the array a->dp /* reallocate the array a->dp
* *
* We store the return in a temporary variable * We store the return in a temporary variable

View File

@ -8,6 +8,7 @@ mp_err mp_init_size(mp_int *a, int size)
{ {
size = MP_MAX(MP_MIN_PREC, size); size = MP_MAX(MP_MIN_PREC, size);
/*TODO*/
/* alloc mem */ /* alloc mem */
a->dp = (mp_digit *) MP_CALLOC((size_t)size, sizeof(mp_digit)); a->dp = (mp_digit *) MP_CALLOC((size_t)size, sizeof(mp_digit));
if (a->dp == NULL) { if (a->dp == NULL) {

View File

@ -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)) { if (MP_HAS(S_MP_LOG_2EXPT) && MP_IS_2EXPT((mp_digit)radix)) {
/* floor(log_{2^n}(a)) + 1 + EOS + sign */ /* floor(log_{2^n}(a)) + 1 + EOS + sign */
*size = (size_t)(s_mp_log_2expt(a, (mp_digit)radix)); *size = (size_t)(s_mp_log_2expt(a, (mp_digit)radix) + 3);
/* Would overflow with base 2 otherwise */
if (*size > (INT_MAX - 4)) {
return MP_VAL;
}
*size += 3u;
return MP_OKAY; return MP_OKAY;
} }