From d9bd3181330830c49e714609e86eaa3e39a884ca Mon Sep 17 00:00:00 2001 From: "Charles.Forsyth" Date: Thu, 12 Jun 2008 21:45:38 +0000 Subject: 20080612-2245 --- libmp/port/mpdiv.c | 2 +- libmp/port/mpfactorial.c | 8 ++++++-- libmp/port/mpinvert.c | 8 +++++--- libmp/port/mptoui.c | 8 +++----- 4 files changed, 15 insertions(+), 11 deletions(-) (limited to 'libmp') 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; } -- cgit v1.2.3