From e87ca8d97689ad9a63c0b56d0bfbda00c56abca2 Mon Sep 17 00:00:00 2001 From: aiju Date: Thu, 26 Apr 2018 14:55:02 +0100 Subject: [PATCH] mpdiv: fix dividing 0 by a small power of two --- sys/src/libmp/port/mpdiv.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sys/src/libmp/port/mpdiv.c b/sys/src/libmp/port/mpdiv.c index ea68acb43..cfd673cfa 100644 --- a/sys/src/libmp/port/mpdiv.c +++ b/sys/src/libmp/port/mpdiv.c @@ -22,7 +22,9 @@ mpdiv(mpint *dividend, mpint *divisor, mpint *quotient, mpint *remainder) // division by one or small powers of two if(divisor->top == 1 && (divisor->p[0] & divisor->p[0]-1) == 0){ - vlong r = (vlong)dividend->sign * (dividend->p[0] & divisor->p[0]-1); + vlong r = 0; + if(dividend->top > 0) + r = (vlong)dividend->sign * (dividend->p[0] & divisor->p[0]-1); if(quotient != nil){ sign = divisor->sign; for(s = 0; ((divisor->p[0] >> s) & 1) == 0; s++)