Compare commits

..

2 Commits

Author SHA1 Message Date
077d3a147a add comments to point at where strict aliasing occurs in data scripts
this is definitely not all of them, a thorough rewrite must take place
to fix as many as we can.
2025-09-03 22:39:15 +02:00
c1dc1b7856 Use void * over u8 *, to be more explicit we're working with raw data, and not just bytes.
The main problem with all my buffer-parsing code so-far is that they
often... always break strict aliasing rules.
Using a `void *` will make these bugs more explicit / noticable.
2025-09-03 22:38:37 +02:00
3 changed files with 7 additions and 7 deletions

View File

@@ -38,14 +38,14 @@ endif
ifeq ($(DEBUG),1)
PROF = dbg
CFLAGS += -UNDEBUG -Og -g -Wextra -Wpedantic
CFLAGS += $(if $(filter 1,$(ISWIN)),,-fsanitize=address,undefined) -ftrapv
LDFLAGS += $(if $(filter 1,$(ISWIN)),,-fsanitize=address,undefined) -ftrapv
CFLAGS += $(if $(filter 1,$(ISWIN)),,-fsanitize=address,undefined)
LDFLAGS += $(if $(filter 1,$(ISWIN)),,-fsanitize=address,undefined)
# |--profile: testing
else ifeq ($(DEBUG),test)
PROF = test
CFLAGS += -UNDEBUG -O2 -g
CFLAGS += $(if $(filter 1,$(ISWIN)),,-fsanitize=address) -ftrapv
LDFLAGS += $(if $(filter 1,$(ISWIN)),,-fsanitize=address) -ftrapv
CFLAGS += $(if $(filter 1,$(ISWIN)),,-fsanitize=address)
LDFLAGS += $(if $(filter 1,$(ISWIN)),,-fsanitize=address)
else
PROF = rel
CFLAGS += -DNDEBUG -O2

View File

@@ -16,7 +16,7 @@
#define CHUNKS 0x400 // amount of chunks in a file
/* Moves chunks `src_s` to `src_e` (inclusive) from `src`, back onto `dst`. */
static void mvchunks(void *restrict buf, void *src, void *dst, int src_s, int src_e) {
static void mvchunks(u8 *restrict buf, void *src, void *dst, int src_s, int src_e) {
assert(src > dst);
u32 *table = (u32 *)buf; // BUG: strict aliasing
size_t len = src - dst; // acquire the amount of bytes that we shall move

View File

@@ -66,7 +66,7 @@ static const void *proclist(const void *restrict buf, struct nbt_array *restrict
}
const void *nbt_proctag(const void *restrict buf, u16 slen, void *restrict out) {
const void *ptr, *tmp;
const u8 *ptr, *tmp;
ptr = buf + 3 + slen;
i32 nmem;
@@ -74,7 +74,7 @@ const void *nbt_proctag(const void *restrict buf, u16 slen, void *restrict out)
// BUG: strict aliasing
switch (*(u8 *)buf) {
case NBT_I8: *(u8 *)out = *(u8 *)ptr; return ptr + 1;
case NBT_I8: *(u8 *)out = *ptr; return ptr + 1;
case NBT_I16: *(u16 *)out = be16toh(*(u16 *)ptr); return ptr + 2;
case NBT_I32: // fall through
case NBT_F32: *(u32 *)out = be16toh(*(u32 *)ptr); return ptr + 4;