mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 14:23:09 +00:00
stage1: detect underflow in bigint_fits_in_bits
This commit is contained in:
parent
d4d509090b
commit
204f8daeed
@ -243,6 +243,7 @@ bool bigint_fits_in_bits(const BigInt *bn, size_t bit_count, bool is_signed) {
|
||||
}
|
||||
|
||||
if (!is_signed) {
|
||||
if(bn->is_negative) return false;
|
||||
size_t full_bits = bn->digit_count * 64;
|
||||
size_t leading_zero_count = bigint_clz(bn, full_bits);
|
||||
return bit_count >= full_bits - leading_zero_count;
|
||||
|
||||
@ -7411,4 +7411,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
, &[_][]const u8{
|
||||
":5:28: error: expected type '[]u8', found '*const [3:0]u8'",
|
||||
});
|
||||
|
||||
cases.add("integer underflow error",
|
||||
\\export fn entry() void {
|
||||
\\ _ = @intToPtr(*c_void, ~@as(usize, @import("std").math.maxInt(usize)) - 1);
|
||||
\\}
|
||||
, &[_][]const u8{
|
||||
":2:75: error: operation caused overflow",
|
||||
});
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user