mirror of
https://github.com/ziglang/zig.git
synced 2026-02-09 11:03:30 +00:00
macho: fix overflowing u64 range
This commit is contained in:
parent
e726868b02
commit
5d4401ceec
@ -2153,8 +2153,13 @@ fn allocateTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64,
|
||||
// Is it enough that we could fit this new text block?
|
||||
const sym = self.local_symbols.items[big_block.local_sym_index];
|
||||
const capacity = big_block.capacity(self.*);
|
||||
const ideal_capacity = capacity * alloc_num / alloc_den;
|
||||
const ideal_capacity_end_vaddr = sym.n_value + ideal_capacity;
|
||||
const ideal_capacity_end_vaddr: u64 = ideal_cap: {
|
||||
if (math.mul(u64, @divTrunc(capacity, alloc_den), alloc_num)) |cap| {
|
||||
break :ideal_cap math.add(u64, sym.n_value, cap) catch math.maxInt(u64);
|
||||
} else |_| {
|
||||
break :ideal_cap math.maxInt(u64);
|
||||
}
|
||||
};
|
||||
const capacity_end_vaddr = sym.n_value + capacity;
|
||||
const new_start_vaddr_unaligned = capacity_end_vaddr - new_block_ideal_capacity;
|
||||
const new_start_vaddr = mem.alignBackwardGeneric(u64, new_start_vaddr_unaligned, alignment);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user