diff options
| author | Charles.Forsyth <devnull@localhost> | 2008-06-12 21:45:38 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2008-06-12 21:45:38 +0000 |
| commit | d9bd3181330830c49e714609e86eaa3e39a884ca (patch) | |
| tree | 9836330fa12c11f4dafce942e3eb23f8fcdf80c9 /libmp | |
| parent | 3d7a0c16959c77d931f7fdd2022945a563bbff10 (diff) | |
20080612-2245
Diffstat (limited to 'libmp')
| -rw-r--r-- | libmp/port/mpdiv.c | 2 | ||||
| -rw-r--r-- | libmp/port/mpfactorial.c | 8 | ||||
| -rw-r--r-- | libmp/port/mpinvert.c | 8 | ||||
| -rw-r--r-- | libmp/port/mptoui.c | 8 |
4 files changed, 15 insertions, 11 deletions
diff --git a/libmp/port/mpdiv.c b/libmp/port/mpdiv.c index 92aee03f..54315ea5 100644 --- a/libmp/port/mpdiv.c +++ b/libmp/port/mpdiv.c @@ -15,7 +15,7 @@ mpdiv(mpint *dividend, mpint *divisor, mpint *quotient, mpint *remainder) // divide bv zero if(divisor->top == 0) - abort(); + sysfatal("mpdiv: divide by zero"); // quick check if(mpmagcmp(dividend, divisor) < 0){ diff --git a/libmp/port/mpfactorial.c b/libmp/port/mpfactorial.c index 01079c44..b0e22ce2 100644 --- a/libmp/port/mpfactorial.c +++ b/libmp/port/mpfactorial.c @@ -42,8 +42,12 @@ mpfactorial(ulong n) max++; if(max > mmax){ mmax++; - if(max > nelem(stk)) - abort(); + if(max >= nelem(stk)){ + while(--max >= 0) + mpfree(stk[max]); + mpfree(r); + sysfatal("mpfactorial: stack overflow"); + } stk[max] = mpnew(Dbits); } stk[max]->top = 1; diff --git a/libmp/port/mpinvert.c b/libmp/port/mpinvert.c index ee263070..45912d6b 100644 --- a/libmp/port/mpinvert.c +++ b/libmp/port/mpinvert.c @@ -9,13 +9,15 @@ void mpinvert(mpint *b, mpint *m, mpint *res) { mpint *dc1, *dc2; // don't care + int r; dc1 = mpnew(0); dc2 = mpnew(0); mpextendedgcd(b, m, dc1, res, dc2); - if(mpcmp(dc1, mpone) != 0) - abort(); - mpmod(res, m, res); + r = mpcmp(dc1, mpone); mpfree(dc1); mpfree(dc2); + if(r != 0) + sysfatal("mpinvert: no inverse"); + mpmod(res, m, res); } diff --git a/libmp/port/mptoui.c b/libmp/port/mptoui.c index 9d80c1df..41c0b0b6 100644 --- a/libmp/port/mptoui.c +++ b/libmp/port/mptoui.c @@ -25,11 +25,9 @@ mptoui(mpint *b) uint x; x = *b->p; - if(b->sign < 0){ + if(b->sign < 0) x = 0; - } else { - if(b->top > 1 || x > MAXUINT) - x = MAXUINT; - } + else if(b->top > 1 || (sizeof(mpdigit) > sizeof(uint) && x > MAXUINT)) + x = MAXUINT; return x; } |
