Fix for integer.c s_mp_add output to make sure it grows if not set.

This commit is contained in:
David Garske
2022-04-21 13:55:19 -07:00
parent 5a75e0f6c6
commit a6a89d3316

View File

@@ -1713,7 +1713,7 @@ int s_mp_add (mp_int * a, mp_int * b, mp_int * c)
}
/* init result */
if (c->alloc < max_ab + 1) {
if (c->dp == NULL || c->alloc < max_ab + 1) {
if ((res = mp_grow (c, max_ab + 1)) != MP_OKAY) {
return res;
}
@@ -1757,7 +1757,7 @@ int s_mp_add (mp_int * a, mp_int * b, mp_int * c)
if (min_ab != max_ab) {
for (; i < max_ab; i++) {
/* T[i] = X[i] + U */
*tmpc = x->dp[i] + u; // NOLINT(clang-analyzer-core.NullDereference) /* clang-tidy 13 false positive */
*tmpc = x->dp[i] + u;
/* U = carry bit of T[i] */
u = *tmpc >> ((mp_digit)DIGIT_BIT);