summaryrefslogtreecommitdiff
path: root/src/piece-table.c
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2025-08-12 00:33:30 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2025-08-12 00:34:07 +0200
commit85088f13c5653174c27f54faac5afd89fbb10655 (patch)
tree9d62f223eb680bdefa9fd40db8ac1e656c727b84 /src/piece-table.c
parent06cddbd263e51a541f46f4cad7037c7ca51e2550 (diff)
piece-table: text-buffer: Fix append on empty case
Diffstat (limited to 'src/piece-table.c')
-rw-r--r--src/piece-table.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/piece-table.c b/src/piece-table.c
index 497c71a..a8ddd1e 100644
--- a/src/piece-table.c
+++ b/src/piece-table.c
@@ -74,9 +74,15 @@ text_buffer_init (text_buffer *tb)
void
text_buffer_append (text_buffer *tb, char c)
{
- if (tb->size == tb->len)
+ size_t base_size = 1024;
+ if (tb->size == 0)
{
- tb->contents = realloc(tb->contents, sizeof(*tb->contents) * tb->len*2);
+ tb->contents = malloc (sizeof(*tb->contents) * base_size);
+ tb->size = base_size;
+ }
+ else if (tb->size == tb->len)
+ {
+ tb->contents = realloc (tb->contents, sizeof(*tb->contents) * tb->len*2);
}
tb->contents[tb->len++] = c;
}