diff options
| -rw-r--r-- | CHANGES | 3 | ||||
| -rw-r--r-- | emu/port/main.c | 5 | ||||
| -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 |
6 files changed, 22 insertions, 12 deletions
@@ -1,3 +1,6 @@ +20080612 + change several libmp/port functions to use sysfatal not abort + change emu/port/main.c to have sysfatal call error not exit 20080611 Keyring->dhparams to use DSAprimes in special case IPint.random now ignores minint (will go next revision) diff --git a/emu/port/main.c b/emu/port/main.c index 35f2a7ec..63c5b1ba 100644 --- a/emu/port/main.c +++ b/emu/port/main.c @@ -421,6 +421,9 @@ _assert(char *fmt) panic("assert failed: %s", fmt); } +/* + * mainly for libmp + */ void sysfatal(char *fmt, ...) { @@ -430,7 +433,7 @@ sysfatal(char *fmt, ...) va_start(arg, fmt); vsnprint(buf, sizeof(buf), fmt, arg); va_end(arg); - panic("sysfatal: %s", buf); + error(buf); } void 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; } |
