From b7a896805dd2fbc4e6e0a0c2fe477efe7e7e7598 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Mon, 9 Oct 2023 14:23:41 +0200 Subject: [PATCH] Fix bug in growable bitset. Always insert 0xAA in malloc on testing. --- lib/std/collections/bitset.c3 | 2 +- lib/std/core/allocators/mem_allocator_fn.c3 | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/std/collections/bitset.c3 b/lib/std/collections/bitset.c3 index cb6beb6d3..a4ff55f81 100644 --- a/lib/std/collections/bitset.c3 +++ b/lib/std/collections/bitset.c3 @@ -139,7 +139,7 @@ fn bool GrowableBitSet.get(&self, usz i) @operator([]) @inline fn usz GrowableBitSet.len(&self) @operator(len) { usz n = self.data.len() * BITS; - if (n > 0) n -= (usz)self.data[n - 1].ctz() - 1; + if (n > 0) n -= (usz)self.data[^1].clz(); return n; } diff --git a/lib/std/core/allocators/mem_allocator_fn.c3 b/lib/std/core/allocators/mem_allocator_fn.c3 index 6ef9eb42b..99f695460 100644 --- a/lib/std/core/allocators/mem_allocator_fn.c3 +++ b/lib/std/core/allocators/mem_allocator_fn.c3 @@ -106,8 +106,14 @@ fn void*! libc_allocator_fn(Allocator* unused, usz bytes, usz alignment, usz off { case ALIGNED_ALLOC: data = @aligned_alloc(libc::malloc, bytes, alignment, offset)!!; + $if env::TESTING: + for (usz i = 0; i < bytes; i++) ((char*)data)[i] = 0xAA; + $endif case ALLOC: data = libc::malloc(bytes); + $if env::TESTING: + for (usz i = 0; i < bytes; i++) ((char*)data)[i] = 0xAA; + $endif case ALIGNED_CALLOC: data = @aligned_calloc(fn void*(usz bytes) => libc::calloc(bytes, 1), bytes, alignment, offset)!!; case CALLOC: