aboutsummaryrefslogtreecommitdiff
path: root/src/big_int.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-07-28 00:48:36 +0100
committergingerBill <bill@gingerbill.org>2018-07-28 00:48:36 +0100
commite34a9e61857a2786abb031d553d4def419f2838c (patch)
tree2becfb73ce3675502e3184c39669e5cb33898113 /src/big_int.cpp
parentc3c783424604b14cdd86950bf4b0aaded1f97316 (diff)
Fix big_int_shr
Diffstat (limited to 'src/big_int.cpp')
-rw-r--r--src/big_int.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/big_int.cpp b/src/big_int.cpp
index c7e3f6a66..a0f3179fe 100644
--- a/src/big_int.cpp
+++ b/src/big_int.cpp
@@ -41,7 +41,7 @@ gb_inline gbAllocator big_int_allocator(void) {
}
void big_int_alloc(BigInt *dst, isize word_len, isize word_cap) {
- GB_ASSERT(word_len <= word_cap);
+ GB_ASSERT_MSG(word_len <= word_cap, "%td %td", word_len, word_cap);
if (word_cap < dst->len) {
dst->len = cast(i32)word_len;
} else {
@@ -605,8 +605,10 @@ void big_int_shr(BigInt *dst, BigInt const *x, BigInt const *y) {
return;
}
- big_int_alloc(dst, cast(i32)(x->len - word_shift_len), dst->len);
- GB_ASSERT(dst->len > 1);
+ i32 len = cast(i32)(x->len - word_shift_len);
+ i32 cap = gb_max(len, dst->len);
+ big_int_alloc(dst, len, cap);
+ GB_ASSERT(dst->len >= 1);
u64 carry = 0;
for (i32 src_idx = x->len - 1; src_idx >= 0; src_idx--) {