Przeglądaj źródła

Fix buddy allocator assert

The last address of "data" is not "cast(uintptr)raw_data(data)+cast(uintptr)size" but
"cast(uintptr)raw_data(data)+cast(uintptr)(size-1)".

The original assert would fail when for example the allocation size requested and the buddy allocator allignment were both 64.
alessio98888 3 tygodni temu
rodzic
commit
c6db3cc670
1 zmienionych plików z 1 dodań i 1 usunięć
  1. 1 1
      core/mem/allocators.odin

+ 1 - 1
core/mem/allocators.odin

@@ -2331,7 +2331,7 @@ buddy_allocator_alloc_bytes_non_zeroed :: proc(b: ^Buddy_Allocator, size: uint)
 		}
 		found.is_free = false
 		data := ([^]byte)(found)[b.alignment:][:size]
-		assert(cast(uintptr)raw_data(data)+cast(uintptr)size < cast(uintptr)buddy_block_next(found), "Buddy_Allocator has made an allocation which overlaps a block header.")
+		assert(cast(uintptr)raw_data(data)+cast(uintptr)(size-1) < cast(uintptr)buddy_block_next(found), "Buddy_Allocator has made an allocation which overlaps a block header.")
 		// ensure_poisoned(data)
 		// sanitizer.address_unpoison(data)
 		return data, nil