Skip to content

Commit

Permalink
Fix bug in growable bitset. Always insert 0xAA in malloc on testing.
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Oct 9, 2023
1 parent 6b571fe commit b7a8968
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/std/collections/bitset.c3
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions lib/std/core/allocators/mem_allocator_fn.c3
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit b7a8968

Please sign in to comment.