aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-09-30 21:31:21 +1000
committerquou <quou@disroot.org>2024-09-30 21:31:21 +1000
commit3aa1183d3f9032d1d17c295e3f3a1dbeab57ab66 (patch)
treefd06404cbd4ee8ed10a04d5bace424b79e71b824
parent800559b72d31126ea6ae787f2b470f7824eafaa3 (diff)
assert that assets are always aligned properly.
-rw-r--r--asset.c6
-rw-r--r--memory.c2
-rw-r--r--memory.h2
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 <stdint.h>
#include <stddef.h>
-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 {