1 #include "tommath_private.h"
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
7 mp_err mp_grow(mp_int *a, int size)
12 /* if the alloc size is smaller alloc more ram */
13 if (a->alloc < size) {
14 /* reallocate the array a->dp
16 * We store the return in a temporary variable
17 * in case the operation failed we don't want
18 * to overwrite the dp member of a.
20 tmp = (mp_digit *) MP_REALLOC(a->dp,
21 (size_t)a->alloc * sizeof(mp_digit),
22 (size_t)size * sizeof(mp_digit));
24 /* reallocation failed but "a" is still valid [can be freed] */
28 /* reallocation succeeded so set a->dp */
31 /* zero excess digits */
34 MP_ZERO_DIGITS(a->dp + i, a->alloc - i);