aboutsummaryrefslogtreecommitdiffstats
path: root/src/math/bigint/divide.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/math/bigint/divide.cpp')
-rw-r--r--src/math/bigint/divide.cpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/math/bigint/divide.cpp b/src/math/bigint/divide.cpp
index 47df1273a..2eb7538db 100644
--- a/src/math/bigint/divide.cpp
+++ b/src/math/bigint/divide.cpp
@@ -38,6 +38,7 @@ void divide(const BigInt& x, const BigInt& y_arg, BigInt& q, BigInt& r)
BigInt y = y_arg;
const u32bit y_words = y.sig_words();
+
r = x;
q = 0;
@@ -51,7 +52,7 @@ void divide(const BigInt& x, const BigInt& y_arg, BigInt& q, BigInt& r)
q = 1;
r = 0;
}
- else
+ else if(compare > 0)
{
u32bit shifts = 0;
word y_top = y[y.sig_words()-1];
@@ -61,6 +62,9 @@ void divide(const BigInt& x, const BigInt& y_arg, BigInt& q, BigInt& r)
const u32bit n = r.sig_words() - 1, t = y_words - 1;
+ if(n < t)
+ throw Internal_Error("BigInt division word sizes");
+
q.get_reg().resize(n - t + 1);
if(n <= t)
{