summaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2023-11-22 16:52:33 -0500
committerTavian Barnes <tavianator@tavianator.com>2023-11-23 13:56:03 -0500
commit3fe1e7ca64bcd3724b00cf399ed9ae6f60e0a008 (patch)
tree75bb5d7ecbbc72edcd88e3d6c19c3e05be848957 /src/alloc.c
parentb9ed3f51d636bb0f182b0cc8a86ebf928b37f8c5 (diff)
downloadbfs-3fe1e7ca64bcd3724b00cf399ed9ae6f60e0a008.tar.xz
alloc: New is_aligned() helper
Diffstat (limited to 'src/alloc.c')
-rw-r--r--src/alloc.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/alloc.c b/src/alloc.c
index ff3ec6d..97f90bc 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -14,7 +14,7 @@
static void *xmemalign(size_t align, size_t size) {
bfs_assert(has_single_bit(align));
bfs_assert(align >= sizeof(void *));
- bfs_assert((size & (align - 1)) == 0);
+ bfs_assert(is_aligned(align, size));
#if __APPLE__
void *ptr = NULL;
@@ -27,7 +27,7 @@ static void *xmemalign(size_t align, size_t size) {
void *alloc(size_t align, size_t size) {
bfs_assert(has_single_bit(align));
- bfs_assert((size & (align - 1)) == 0);
+ bfs_assert(is_aligned(align, size));
if (size >> (SIZE_WIDTH - 1)) {
errno = EOVERFLOW;
@@ -43,7 +43,7 @@ void *alloc(size_t align, size_t size) {
void *zalloc(size_t align, size_t size) {
bfs_assert(has_single_bit(align));
- bfs_assert((size & (align - 1)) == 0);
+ bfs_assert(is_aligned(align, size));
if (size >> (SIZE_WIDTH - 1)) {
errno = EOVERFLOW;
@@ -90,7 +90,7 @@ static void chunk_set_next(const struct arena *arena, union chunk *chunk, union
void arena_init(struct arena *arena, size_t align, size_t size) {
bfs_assert(has_single_bit(align));
- bfs_assert((size & (align - 1)) == 0);
+ bfs_assert(is_aligned(align, size));
if (align < alignof(union chunk)) {
align = alignof(union chunk);
@@ -98,7 +98,7 @@ void arena_init(struct arena *arena, size_t align, size_t size) {
if (size < sizeof(union chunk)) {
size = sizeof(union chunk);
}
- bfs_assert((size & (align - 1)) == 0);
+ bfs_assert(is_aligned(align, size));
arena->chunks = NULL;
arena->nslabs = 0;