summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-11-14 21:17:31 -0800
committerKaz Kylheku <kaz@kylheku.com>2016-11-14 21:17:31 -0800
commitc30a96120f53b960db56bc05a7ce6310bb2528f5 (patch)
tree09684ea3e25ac325977cf6f04b7658ef7089a49a
parent0c7ab22f4ea9541514782694ea2a64485d72f0a3 (diff)
downloadtxr-c30a96120f53b960db56bc05a7ce6310bb2528f5.tar.gz
txr-c30a96120f53b960db56bc05a7ce6310bb2528f5.tar.bz2
txr-c30a96120f53b960db56bc05a7ce6310bb2528f5.zip
Fix bug in bignum addition.
* mpi/mpi.c (s_mp_add): It looks like this function had the same kind of bug I fixed years ago in the multiplication routines. ("fix-mult-bug" patch, originally). In the main loop, two digit-sized values are added together to produce a partial sum with carry. Unfortunately, both operands digit-sized, so the result is truncated to the digit type. The cast of one of the operands to mp_word is missing.
-rw-r--r--mpi/mpi.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/mpi/mpi.c b/mpi/mpi.c
index 1e236e26..aea72585 100644
--- a/mpi/mpi.c
+++ b/mpi/mpi.c
@@ -4130,7 +4130,7 @@ mp_err s_mp_add(mp_int *a, mp_int *b) /* magnitude addition */
pa = DIGITS(a);
pb = DIGITS(b);
for(ix = 0; ix < used; ++ix) {
- w += *pa + *pb++;
+ w += *pa + convert(mp_word, *pb++);
*pa++ = ACCUM(w);
w = CARRYOUT(w);
}