diff --git a/crypto/common/bigint.hpp b/crypto/common/bigint.hpp
index 07ccc7d1..e78f4892 100644
--- a/crypto/common/bigint.hpp
+++ b/crypto/common/bigint.hpp
@@ -1312,7 +1312,10 @@ bool AnyIntView
::mod_div_any(const AnyIntView
& yp, AnyIntView
& quot,
if (k > quot.max_size()) {
return invalidate_bool();
}
- quot.set_size(k);
+ quot.set_size(max(k,1));
+ for(int qi=0; qi< max(k,1); qi++) {
+ quot.digits[qi]=0;
+ }
} else {
if (k >= quot.max_size()) {
return invalidate_bool();