Coverage Report

Created: 2026-04-12 06:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dropbear/libtommath/bn_mp_grow.c
Line
Count
Source
1
#include "tommath_private.h"
2
#ifdef BN_MP_GROW_C
3
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
4
/* SPDX-License-Identifier: Unlicense */
5
6
/* grow as required */
7
mp_err mp_grow(mp_int *a, int size)
8
256k
{
9
256k
   int     i;
10
256k
   mp_digit *tmp;
11
12
256k
   if (size < 0) {
13
0
      return MP_VAL;
14
0
   }
15
16
   /* if the alloc size is smaller alloc more ram */
17
256k
   if (a->alloc < size) {
18
      /* reallocate the array a->dp
19
       *
20
       * We store the return in a temporary variable
21
       * in case the operation failed we don't want
22
       * to overwrite the dp member of a.
23
       */
24
253k
      tmp = (mp_digit *) MP_REALLOC(a->dp,
25
253k
                                    (size_t)a->alloc * sizeof(mp_digit),
26
253k
                                    (size_t)size * sizeof(mp_digit));
27
253k
      if (tmp == NULL) {
28
         /* reallocation failed but "a" is still valid [can be freed] */
29
0
         return MP_MEM;
30
0
      }
31
32
      /* reallocation succeeded so set a->dp */
33
253k
      a->dp = tmp;
34
35
      /* zero excess digits */
36
253k
      i        = a->alloc;
37
253k
      a->alloc = size;
38
253k
      MP_ZERO_DIGITS(a->dp + i, a->alloc - i);
39
253k
   }
40
256k
   return MP_OKAY;
41
256k
}
42
#endif