mirror of
https://github.com/thepigeongenerator/mcaselector-lite
synced 2026-02-07 23:28:09 +01:00
Add comment annotations
This commit is contained in:
@@ -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
|
blen = slen * SECTOR; // compute the byte length of the chunk
|
||||||
|
|
||||||
// reset the table data
|
// reset the table data
|
||||||
table[sidx] = 0;
|
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
|
// WARN: might need to zero-out the timestamp instead
|
||||||
|
table[sidx + CHUNKS] = cvt_htobe32(time(NULL));
|
||||||
|
|
||||||
// move the succeeding chunks over the deleted chunk
|
// move the succeeding chunks over the deleted chunk
|
||||||
u8 *dst = buf + bidx - rmb;
|
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));
|
memcpy(table, buf, sizeof(table));
|
||||||
u8 *dst = buf + (cvt_be32toh(table[start]) >> 8) * SECTOR;
|
u8 *dst = buf + (cvt_be32toh(table[start]) >> 8) * SECTOR;
|
||||||
u8 *src = buf + (cvt_be32toh(table[end]) >> 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;
|
src += (cvt_be32toh(table[end]) & 0xFF) * SECTOR;
|
||||||
|
|
||||||
// zeroes-out the chunk data within this range. (and set the timestamp)
|
// 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));
|
be32 ts = cvt_htobe32(time(NULL));
|
||||||
for (int i = start; i <= end; i++) {
|
for (int i = start; i <= end; i++) {
|
||||||
table[i] = 0;
|
table[i] = 0;
|
||||||
@@ -146,6 +149,7 @@ usize mcx_delchunk_range(u8 *restrict buf, int start, int end)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// move the remaining chunks down
|
// move the remaining chunks down
|
||||||
|
// BUG: Chunks may not necessarily be stored in order.
|
||||||
if (end < (CHUNKS - 1))
|
if (end < (CHUNKS - 1))
|
||||||
mvchunks(dst, src, table, end, (CHUNKS - 1));
|
mvchunks(dst, src, table, end, (CHUNKS - 1));
|
||||||
memcpy(buf, table, sizeof(table));
|
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. */
|
* Multiplying by `SECTOR`, and adding the size of the table itself. */
|
||||||
usize mcx_calcsize(const u8 *restrict buf)
|
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;
|
usize size = 0;
|
||||||
for (uint i = 0; i < CHUNKS; i++)
|
for (uint i = 0; i < CHUNKS; i++)
|
||||||
size += *(buf + (i * 4) + 3);
|
size += *(buf + (i * 4) + 3);
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ static const u8 *procarr(const u8 *restrict buf, s32 nmemb, uint size, struct nb
|
|||||||
s32 i = 0;
|
s32 i = 0;
|
||||||
while (i < nmemb) {
|
while (i < nmemb) {
|
||||||
switch (size) {
|
switch (size) {
|
||||||
|
// BUG: Violation of strict aliasing
|
||||||
case 2: ((u16 *)out->dat)[i] = cvt_be16toh(((u16 *)out->dat)[i]); break;
|
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 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;
|
case 8: ((u64 *)out->dat)[i] = cvt_be16toh(((u64 *)out->dat)[i]); break;
|
||||||
|
|||||||
Reference in New Issue
Block a user