diff options
| author | cinap_lenrek <cinap_lenrek@felloff.net> | 2017-02-05 02:50:11 +0100 |
|---|---|---|
| committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2017-02-05 02:50:11 +0100 |
| commit | 541528252ef042f082c82edf47af7d4947b2f661 (patch) | |
| tree | 9124195977ce5be33aeaf913786a386c2b38a9e0 | |
| parent | 3b24eb4c1f4f7bccd6335002e0e37b98a54bf7fd (diff) | |
| parent | 96769e04765511047981e7962d91b979e841f01f (diff) | |
| download | plan9front-541528252ef042f082c82edf47af7d4947b2f661.tar.xz | |
merge
| -rw-r--r-- | sys/src/libmp/port/mpmod.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/sys/src/libmp/port/mpmod.c b/sys/src/libmp/port/mpmod.c index c02f72c9a..9ed17593c 100644 --- a/sys/src/libmp/port/mpmod.c +++ b/sys/src/libmp/port/mpmod.c @@ -6,11 +6,15 @@ void 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); + } } |
