terminal: RefCountedSize should use usize for byte math

Related to #1873
This commit is contained in:
Mitchell Hashimoto
2024-06-24 10:39:55 -07:00
parent 06db3ba9e3
commit d019bacb18
2 changed files with 9 additions and 2 deletions

View File

@ -141,10 +141,12 @@ pub fn RefCountedSet(
const items_cap: Id = @intFromFloat(load_factor * @as(f64, @floatFromInt(table_cap))); const items_cap: Id = @intFromFloat(load_factor * @as(f64, @floatFromInt(table_cap)));
const table_start = 0; const table_start = 0;
const table_end = table_start + table_cap * @sizeOf(Id); const table_cap_usize: usize = @intCast(table_cap);
const table_end = table_start + table_cap_usize * @sizeOf(Id);
const items_start = std.mem.alignForward(usize, table_end, @alignOf(Item)); const items_start = std.mem.alignForward(usize, table_end, @alignOf(Item));
const items_end = items_start + items_cap * @sizeOf(Item); const items_cap_usize: usize = @intCast(items_cap);
const items_end = items_start + items_cap_usize * @sizeOf(Item);
const total_size = items_end; const total_size = items_end;

View File

@ -314,3 +314,8 @@ test "Set basic usage" {
set.release(buf, id); set.release(buf, id);
try testing.expect(set.refCount(buf, id) == 0); try testing.expect(set.refCount(buf, id) == 0);
} }
test "Set capacities" {
// We want to support at least this many styles without overflowing.
_ = Set.layout(16384);
}