int toplen = len/2, botlen = len - toplen; /* botlen is the bigger */
int midlen = botlen + 1;
BignumDblInt carry;
-#ifdef KARA_DEBUG
- int i;
-#endif
/*
* The coefficients a_1 b_1 and a_0 b_0 just avoid overlapping
pqlen = (p[0] > q[0] ? p[0] : q[0]);
+ /* Make sure that we're allowing enough space. The shifting below will
+ * underflow the vectors we allocate if `pqlen' is too small.
+ */
+ if (2*pqlen <= mlen)
+ pqlen = mlen/2 + 1;
+
/* Allocate n of size pqlen, copy p to n */
n = snewn(pqlen, BignumInt);
i = pqlen - p[0];