aboutsummaryrefslogtreecommitdiff
path: root/src/bigint.cpp
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2019-04-26 15:57:47 +0200
committerAndrew Kelley <andrew@ziglang.org>2019-04-26 14:24:35 -0400
commit9ec4ccc68f6473ce4f02fc5d2b87ad92e2eb555a (patch)
treee11ad31594fe66fcfa449960f4b128ec9315d93e /src/bigint.cpp
parent4df2f3d74f140ae6a60dc33d3e0fb7b25f29d5b9 (diff)
downloadzig-9ec4ccc68f6473ce4f02fc5d2b87ad92e2eb555a.tar.gz
zig-9ec4ccc68f6473ce4f02fc5d2b87ad92e2eb555a.zip
Do not invoke UB in BigInt shr operations
Shifting a value of type T by an amount that's greater or equal to the size of the type itself is UB. Spotted by @tgschultz
Diffstat (limited to 'src/bigint.cpp')
-rw-r--r--src/bigint.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/bigint.cpp b/src/bigint.cpp
index dcd9dfc0bd..da53a2b129 100644
--- a/src/bigint.cpp
+++ b/src/bigint.cpp
@@ -1395,7 +1395,7 @@ void bigint_shr(BigInt *dest, const BigInt *op1, const BigInt *op2) {
uint64_t shift_amt = bigint_as_unsigned(op2);
if (op1->digit_count == 1) {
- dest->data.digit = op1_digits[0] >> shift_amt;
+ dest->data.digit = (shift_amt < 64) ? op1_digits[0] >> shift_amt : 0;
dest->digit_count = 1;
dest->is_negative = op1->is_negative;
bigint_normalize(dest);