diff options
author | pcpa <paulo.cesar.pereira.de.andrade@gmail.com> | 2012-05-24 15:26:50 -0300 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2012-05-31 23:00:34 -0700 |
commit | 63c70c830c79f0b4cfc0f7393662a9cb1169973e (patch) | |
tree | 9d68dc0b5c22af5da916854627566be8b7d78d48 /lisp/mp/mpi.c | |
parent | c110109f1710758d7c87c05720bdff4df316fc7d (diff) |
Correct 64 bit overflow check and bignum code.
Signed-off-by: pcpa <paulo.cesar.pereira.de.andrade@gmail.com>
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'lisp/mp/mpi.c')
-rw-r--r-- | lisp/mp/mpi.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lisp/mp/mpi.c b/lisp/mp/mpi.c index fabe366..447bd23 100644 --- a/lisp/mp/mpi.c +++ b/lisp/mp/mpi.c @@ -318,7 +318,7 @@ mpi_setstr(mpi *rop, char *str, int base) if (islower(value)) value = toupper(value); value = value > '9' ? value - 'A' + 10 : value - '0'; - value += rop->digs[0] * base; + value += (BNI)rop->digs[0] * base; carry = value >> BNSBITS; rop->digs[0] = (BNS)value; for (i = 1; i < size; i++) { @@ -642,10 +642,10 @@ mpi_divqr(mpi *qrop, mpi *rrop, mpi *num, mpi *den) if (ndigs[npos] == ddigs[dpos]) qest = (BNS)SMASK; else - qest = (BNS)((((BNI)(ndigs[npos]) << 16) + ndigs[npos - 1]) / + qest = (BNS)((((BNI)(ndigs[npos]) << BNSBITS) + ndigs[npos - 1]) / ddigs[dpos]); - while ((value = ((BNI)(ndigs[npos]) << 16) + ndigs[npos - 1] - + while ((value = ((BNI)(ndigs[npos]) << BNSBITS) + ndigs[npos - 1] - qest * (BNI)(ddigs[dpos])) < CARRY && ddigs[dpos - 1] * (BNI)qest > (value << BNSBITS) + ndigs[npos - 2]) @@ -1603,7 +1603,7 @@ mpi_getstr(char *str, mpi *op, int base) /* make copy of op data and adjust digs */ xdigs = mp_malloc(size * sizeof(BNS)); - memcpy(xdigs, op->digs, size * sizeof(unsigned short)); + memcpy(xdigs, op->digs, size * sizeof(BNS)); digs = xdigs + size - 1; /* convert to string */ |