AmendHub

Download (as of this amendment):

jcs

/

textview

/

amendments

/

15

Fix carrying over of free_length to new chunks


jcs made amendment 15 over 2 years ago
--- textview.c Mon Oct 7 16:05:19 2024 +++ textview.c Tue Oct 8 09:17:51 2024 @@ -140,6 +140,7 @@ TVCreateChunk(struct TVRec *tv, unsigned long length) /* TODO: try to allocate a smaller chunk */ panic("malloc(%ld) failed", (unsigned long)CHUNK_ALLOC_SIZE); chunk->mallocked = true; + chunk->free_length = CHUNK_ALLOC_SIZE - sizeof(struct TVStyle); } else { /* create new chunk in existing alloc */ addr = (unsigned long)tv->cur_chunk + sizeof(struct TVChunk) + @@ -147,10 +148,11 @@ TVCreateChunk(struct TVRec *tv, unsigned long length) if (addr % 2 != 0) addr++; chunk = (struct TVChunk *)addr; + memset(chunk, 0, sizeof(struct TVChunk)); + chunk->free_length = tv->cur_chunk->free_length - + sizeof(struct TVStyle); } - memset(chunk, 0, sizeof(struct TVChunk)); - chunk->free_length = CHUNK_ALLOC_SIZE - sizeof(struct TVChunk); chunk->line = tv->cur_chunk->line; chunk->rect.top = tv->cur_chunk->rect.top; chunk->rect.left = chunk->rect.right = tv->cur_chunk->rect.right; --- textview.h Mon Oct 7 16:06:12 2024 +++ textview.h Mon Oct 7 16:45:25 2024 @@ -38,16 +38,16 @@ typedef struct BigRect BigRect; (br).bottom = (r).bottom; ) struct TVChunk { - unsigned long length; struct TVChunk *prev_chunk; struct TVChunk *next_chunk; unsigned long free_length; unsigned long line; - unsigned long sel_start; - unsigned long sel_finish; - struct TVStyle style; - unsigned long baseline; BigRect rect; + unsigned short length; + unsigned short sel_start; + unsigned short sel_finish; + unsigned short baseline; + struct TVStyle style; bool mallocked; char text[]; };