summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLibravatar Martin Michalec <martin@michalec.dev>2026-02-22 03:09:16 +0000
committerLibravatar Martin Michalec <martin@michalec.dev>2026-02-22 03:09:16 +0000
commitb9ee6745502012d5c7399fc9996ed2d8007d43cd (patch)
tree512655d91d278666266a93fcce887af313542b19 /src
parentadd implementation (diff)
downloadarena-b9ee6745502012d5c7399fc9996ed2d8007d43cd.tar.gz
fix size counting bug in arena__coalesce_from_fast
Diffstat (limited to 'src')
-rw-r--r--src/arena.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/arena.c b/src/arena.c
index bd93eeb..d02694d 100644
--- a/src/arena.c
+++ b/src/arena.c
@@ -23,6 +23,12 @@ chunk_size (struct arena__chunk *chunk)
23 return chunk->end - chunk->data; 23 return chunk->end - chunk->data;
24} 24}
25 25
26static size_t
27chunk_used (struct arena__chunk *chunk)
28{
29 return chunk->free - chunk->data;
30}
31
26static struct arena__chunk * 32static struct arena__chunk *
27new_chunk (size_t size) 33new_chunk (size_t size)
28{ 34{
@@ -206,11 +212,13 @@ arena__coalesce_from_fast (ARENA arena, struct arena__checkpoint checkpoint,
206 212
207 // copy old chunks into new chunk 213 // copy old chunks into new chunk
208 size_t other_size = checkpoint.tail->free - checkpoint.free; 214 size_t other_size = checkpoint.tail->free - checkpoint.free;
209 memcpy (chunk->free, checkpoint.free, other_size); 215 if (other_size) {
210 chunk->free += other_size; 216 memcpy (chunk->free, checkpoint.free, other_size);
217 chunk->free += other_size;
218 }
211 for (struct arena__chunk *other_chunk = checkpoint.tail->next; 219 for (struct arena__chunk *other_chunk = checkpoint.tail->next;
212 other_chunk; other_chunk = other_chunk->next) { 220 other_chunk; other_chunk = other_chunk->next) {
213 other_size = chunk_size (other_chunk); 221 other_size = chunk_used (other_chunk);
214 memcpy (chunk->free, other_chunk->data, other_size); 222 memcpy (chunk->free, other_chunk->data, other_size);
215 chunk->free += other_size; 223 chunk->free += other_size;
216 } 224 }