In mpi_copy(), any failure should leave the target untouched.

This commit is contained in:
Dag-Erling Smørgrav 2014-12-29 23:18:57 +00:00 committed by des
parent b2ec312d9f
commit 8228f19d5a

View file

@ -136,9 +136,13 @@ mpi_copy(cryb_mpi *X, const cryb_mpi *Y)
if (X == Y) if (X == Y)
return (0); return (0);
mpi_zero(X); if (Y->msb == 0) {
mpi_zero(X);
return (0);
}
if (mpi_grow(X, Y->msb) != 0) if (mpi_grow(X, Y->msb) != 0)
return (-1); return (-1);
mpi_zero(X);
X->msb = Y->msb; X->msb = Y->msb;
X->neg = Y->neg; X->neg = Y->neg;
memcpy(X->words, Y->words, X->size * sizeof *X->words); memcpy(X->words, Y->words, X->size * sizeof *X->words);