ref: 541528252ef042f082c82edf47af7d4947b2f661
parent: 3b24eb4c1f4f7bccd6335002e0e37b98a54bf7fd
parent: 96769e04765511047981e7962d91b979e841f01f
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sat Feb 4 21:50:11 EST 2017
merge
--- a/sys/src/libmp/port/mpmod.c
+++ b/sys/src/libmp/port/mpmod.c
@@ -6,11 +6,15 @@
mpmod(mpint *x, mpint *n, mpint *r)
{
int sign;
+ mpint *ns;
sign = x->sign;
+ ns = sign < 0 && n == r ? mpcopy(n) : n;
if((n->flags & MPfield) == 0
|| ((Mfield*)n)->reduce((Mfield*)n, x, r) != 0)
mpdiv(x, n, nil, r);
- if(sign < 0)
- mpmagsub(n, r, r);
+ if(sign < 0){
+ mpmagsub(ns, r, r);
+ if(ns != n) mpfree(ns);
+ }
}