From 3518df8191beaa938c1847a56a688b40313f9a30 Mon Sep 17 00:00:00 2001 From: Quinn Date: Thu, 22 Jan 2026 17:36:27 +0100 Subject: [PATCH] Add comment annotations --- src/dat/mcx.c | 11 +++++++++-- src/dat/nbt.c | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/dat/mcx.c b/src/dat/mcx.c index 0c23d97..235d302 100644 --- a/src/dat/mcx.c +++ b/src/dat/mcx.c @@ -107,8 +107,9 @@ static usize delchunk(u8 *restrict buf, be32 *restrict table, usize rmb, int sid blen = slen * SECTOR; // compute the byte length of the chunk // reset the table data - table[sidx] = 0; - table[sidx + CHUNKS] = cvt_htobe32(time(NULL)); // assign the current time to the timestamp, for correctness NOTE: might need to zero-out instead + table[sidx] = 0; + // WARN: might need to zero-out the timestamp instead + table[sidx + CHUNKS] = cvt_htobe32(time(NULL)); // move the succeeding chunks over the deleted chunk u8 *dst = buf + bidx - rmb; @@ -136,9 +137,11 @@ usize mcx_delchunk_range(u8 *restrict buf, int start, int end) memcpy(table, buf, sizeof(table)); u8 *dst = buf + (cvt_be32toh(table[start]) >> 8) * SECTOR; u8 *src = buf + (cvt_be32toh(table[end]) >> 8) * SECTOR; + // BUG: We are selecting the wrong byte for this. src += (cvt_be32toh(table[end]) & 0xFF) * SECTOR; // zeroes-out the chunk data within this range. (and set the timestamp) + // WARN: May need to zero-out the timestamp instead. be32 ts = cvt_htobe32(time(NULL)); for (int i = start; i <= end; i++) { table[i] = 0; @@ -146,6 +149,7 @@ usize mcx_delchunk_range(u8 *restrict buf, int start, int end) } // move the remaining chunks down + // BUG: Chunks may not necessarily be stored in order. if (end < (CHUNKS - 1)) mvchunks(dst, src, table, end, (CHUNKS - 1)); memcpy(buf, table, sizeof(table)); @@ -185,6 +189,9 @@ usize mcx_delchunk_bulk(u8 *restrict buf, const u16 *restrict chunks, int chunkc * Multiplying by `SECTOR`, and adding the size of the table itself. */ usize mcx_calcsize(const u8 *restrict buf) { + /* NOTE: This can be optimised if chunks are always + * in order. I.e. we can guarantee that the last chunk in + * the table has the greatest offset. */ usize size = 0; for (uint i = 0; i < CHUNKS; i++) size += *(buf + (i * 4) + 3); diff --git a/src/dat/nbt.c b/src/dat/nbt.c index 658a11f..f1d71d1 100644 --- a/src/dat/nbt.c +++ b/src/dat/nbt.c @@ -62,6 +62,7 @@ static const u8 *procarr(const u8 *restrict buf, s32 nmemb, uint size, struct nb s32 i = 0; while (i < nmemb) { switch (size) { + // BUG: Violation of strict aliasing case 2: ((u16 *)out->dat)[i] = cvt_be16toh(((u16 *)out->dat)[i]); break; case 4: ((u32 *)out->dat)[i] = cvt_be16toh(((u32 *)out->dat)[i]); break; case 8: ((u64 *)out->dat)[i] = cvt_be16toh(((u64 *)out->dat)[i]); break;