mp_sub_d (integer.c): return error when digit is too big

Code can't handle subtracting a number (an mp_digit) larger than
DIGIT_BIT. Now returns an error rather than giving wrong result.
This commit is contained in:
Sean Parkinson
2020-07-14 09:11:24 +10:00
parent 1caa6f860b
commit ddad95d52c
2 changed files with 3 additions and 1 deletions

View File

@@ -4324,6 +4324,8 @@ int mp_sub_d (mp_int * a, mp_digit b, mp_int * c)
mp_digit *tmpa, *tmpc, mu;
int res, ix, oldused;
if (b > MP_MASK) return MP_VAL;
/* grow c as required */
if (c->alloc < a->used + 1) {
if ((res = mp_grow(c, a->used + 1)) != MP_OKAY) {