From 3aa1183d3f9032d1d17c295e3f3a1dbeab57ab66 Mon Sep 17 00:00:00 2001 From: quou Date: Mon, 30 Sep 2024 21:31:21 +1000 Subject: assert that assets are always aligned properly. --- asset.c | 6 +++++- memory.c | 2 +- memory.h | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/asset.c b/asset.c index 31a6d8c..9b5b0fb 100644 --- a/asset.c +++ b/asset.c @@ -1,8 +1,12 @@ +#include "memory.h" #include "pack.h" +#include "plat.h" #include "asset.h" const unsigned char* get_asset(Asset_ID id) { - return &asset_data[asset_offset_table[id]]; + const void* ptr = &asset_data[asset_offset_table[id]]; + assert(aligned(ptr, allocation_default_alignment)); + return ptr; } const struct Bitmap* get_bitmap(Asset_ID id) { diff --git a/memory.c b/memory.c index b5c6a70..91e4a5b 100644 --- a/memory.c +++ b/memory.c @@ -3,7 +3,7 @@ #include #include -int aligned(void* p, int a) { +int aligned(const void* p, int a) { return (uintptr_t)p % a == 0; } diff --git a/memory.h b/memory.h index 38e632a..26c0382 100644 --- a/memory.h +++ b/memory.h @@ -1,7 +1,7 @@ #ifndef memory_h #define memory_h -int aligned(void* p, int a); +int aligned(const void* p, int a); int align_size(int s, int a); typedef struct Arena { -- cgit v1.2.3-54-g00ecf