libtommath: allow mp_shrink to shrink initialized, but empty MPI's
from https://github.com/libtom/libtommath Change-Id: I5814caeb44db710957152a7d47b03f9beb6e5147
This commit is contained in:

committed by
Jeffrey Altman

parent
28051fa99c
commit
5bc653f0ef
@@ -19,12 +19,17 @@
|
|||||||
int mp_shrink (mp_int * a)
|
int mp_shrink (mp_int * a)
|
||||||
{
|
{
|
||||||
mp_digit *tmp;
|
mp_digit *tmp;
|
||||||
if (a->alloc != a->used && a->used > 0) {
|
int used = 1;
|
||||||
if ((tmp = OPT_CAST(mp_digit) XREALLOC (a->dp, sizeof (mp_digit) * a->used)) == NULL) {
|
|
||||||
|
if(a->used > 0)
|
||||||
|
used = a->used;
|
||||||
|
|
||||||
|
if (a->alloc != used) {
|
||||||
|
if ((tmp = OPT_CAST(mp_digit) XREALLOC (a->dp, sizeof (mp_digit) * used)) == NULL) {
|
||||||
return MP_MEM;
|
return MP_MEM;
|
||||||
}
|
}
|
||||||
a->dp = tmp;
|
a->dp = tmp;
|
||||||
a->alloc = a->used;
|
a->alloc = used;
|
||||||
}
|
}
|
||||||
return MP_OKAY;
|
return MP_OKAY;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user