Compare commits

..

3 Commits

Author SHA1 Message Date
942ffdc857 add a flag when debugging to generate SIGFPE when signed integer overflow occurs. (this is UB) 2025-09-04 10:41:42 +02:00
4bf02b2d03 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-04 10:41:42 +02:00
bc4855e063 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-04 10:41:42 +02:00
3 changed files with 7 additions and 7 deletions

View File

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

View File

@@ -16,7 +16,7 @@
#define CHUNKS 0x400 // amount of chunks in a file #define CHUNKS 0x400 // amount of chunks in a file
/* Moves chunks `src_s` to `src_e` (inclusive) from `src`, back onto `dst`. */ /* Moves chunks `src_s` to `src_e` (inclusive) from `src`, back onto `dst`. */
static void mvchunks(u8 *restrict buf, void *src, void *dst, int src_s, int src_e) { static void mvchunks(void *restrict buf, void *src, void *dst, int src_s, int src_e) {
assert(src > dst); assert(src > dst);
u32 *table = (u32 *)buf; // BUG: strict aliasing u32 *table = (u32 *)buf; // BUG: strict aliasing
size_t len = src - dst; // acquire the amount of bytes that we shall move 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 *nbt_proctag(const void *restrict buf, u16 slen, void *restrict out) {
const u8 *ptr, *tmp; const void *ptr, *tmp;
ptr = buf + 3 + slen; ptr = buf + 3 + slen;
i32 nmem; i32 nmem;
@@ -74,7 +74,7 @@ const void *nbt_proctag(const void *restrict buf, u16 slen, void *restrict out)
// BUG: strict aliasing // BUG: strict aliasing
switch (*(u8 *)buf) { switch (*(u8 *)buf) {
case NBT_I8: *(u8 *)out = *ptr; return ptr + 1; case NBT_I8: *(u8 *)out = *(u8 *)ptr; return ptr + 1;
case NBT_I16: *(u16 *)out = be16toh(*(u16 *)ptr); return ptr + 2; case NBT_I16: *(u16 *)out = be16toh(*(u16 *)ptr); return ptr + 2;
case NBT_I32: // fall through case NBT_I32: // fall through
case NBT_F32: *(u32 *)out = be16toh(*(u32 *)ptr); return ptr + 4; case NBT_F32: *(u32 *)out = be16toh(*(u32 *)ptr); return ptr + 4;