From 85088f13c5653174c27f54faac5afd89fbb10655 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Tue, 12 Aug 2025 00:33:30 +0200 Subject: piece-table: text-buffer: Fix append on empty case --- src/piece-table.c | 10 ++++++++-- 1 file 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; } -- cgit v1.2.3