authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-05-11 14:06:37+02:00
committergravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-05-11 14:06:37+02:00
log204f8daeeda02738479e0d586e6426e23f78e6cc
treecd38de48598d099b4fa8596f003cd536494671d9
parentd4d509090b47a3860831a0fb6fb7fae02f5f7857

stage1: detect underflow in bigint_fits_in_bits


2 files changed, 9 insertions(+), 0 deletions(-)

src/bigint.cpp+1
......@@ -243,6 +243,7 @@ bool bigint_fits_in_bits(const BigInt *bn, size_t bit_count, bool is_signed) {
243243 }
244244
245245 if (!is_signed) {
246 if(bn->is_negative) return false;
246247 size_t full_bits = bn->digit_count * 64;
247248 size_t leading_zero_count = bigint_clz(bn, full_bits);
248249 return bit_count >= full_bits - leading_zero_count;
test/compile_errors.zig+8
......@@ -7411,4 +7411,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
74117411 , &[_][]const u8{
74127412 ":5:28: error: expected type '[]u8', found '*const [3:0]u8'",
74137413 });
7414
7415 cases.add("integer underflow error",
7416 \\export fn entry() void {
7417 \\ _ = @intToPtr(*c_void, ~@as(usize, @import("std").math.maxInt(usize)) - 1);
7418 \\}
7419 , &[_][]const u8{
7420 ":2:75: error: operation caused overflow",
7421 });
74147422}