From 2fe68eb9734e35fa720730b8f6c2f35a26be556f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 13 Mar 2024 17:30:15 -0700 Subject: [PATCH] terminal: bitmap allocator had off by one on extra bitmaps --- src/terminal-old/modes.zig | 2 +- src/terminal/bitmap_allocator.zig | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/terminal-old/modes.zig b/src/terminal-old/modes.zig index e42efa16e..c9ed84cbd 100644 --- a/src/terminal-old/modes.zig +++ b/src/terminal-old/modes.zig @@ -89,7 +89,7 @@ pub const ModePacked = packed_struct: { } break :packed_struct @Type(.{ .Struct = .{ - .layout = .Packed, + .layout = .@"packed", .fields = &fields, .decls = &.{}, .is_tuple = false, diff --git a/src/terminal/bitmap_allocator.zig b/src/terminal/bitmap_allocator.zig index 242575f9f..9d45327cb 100644 --- a/src/terminal/bitmap_allocator.zig +++ b/src/terminal/bitmap_allocator.zig @@ -76,6 +76,7 @@ pub fn BitmapAllocator(comptime chunk_size: comptime_int) type { // fixed but we haven't needed it. Contributor friendly: add tests // and fix this. assert(chunk_size % @alignOf(T) == 0); + assert(n > 0); const byte_count = std.math.mul(usize, @sizeOf(T), n) catch return error.OutOfMemory; @@ -193,7 +194,7 @@ fn findFreeChunks(bitmaps: []u64, n: usize) ?usize { bitmap.* ^= mask; } - return (idx * 63) + bit; + return (idx * 64) + bit; } return null; @@ -229,7 +230,7 @@ test "findFreeChunks multiple found" { 0b10000000_00111110_00000000_00000000_00000000_00000000_00111110_00000000, }; const idx = findFreeChunks(&bitmaps, 4).?; - try testing.expectEqual(@as(usize, 72), idx); + try testing.expectEqual(@as(usize, 73), idx); try testing.expectEqual( 0b10000000_00111110_00000000_00000000_00000000_00000000_00100000_00000000, bitmaps[1],