From 5dd98385e03b9cc7c912b1b50f7c406df117a9af Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Tue, 12 Aug 2025 00:35:18 +0200 Subject: piece-table: Don't allocate in piece_table_to_string `piece_table_to_string` now receives a buffer and we also provide a function that returns the length of the piece table. TODO: the `piece_table_to_string` adds null termination, that makes the buffer needed `piece_table_length(pt) + 1`. This we should document or do more obvious. --- tests/piece-table-delete.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'tests/piece-table-delete.c') diff --git a/tests/piece-table-delete.c b/tests/piece-table-delete.c index c883b34..dc54ccc 100644 --- a/tests/piece-table-delete.c +++ b/tests/piece-table-delete.c @@ -6,27 +6,33 @@ int main() { piece_table *pt = piece_table_create("0123456789"); + char tmp[100]; + piece_table_delete(pt, 0, 10); - if (strcmp(piece_table_to_string(pt), "")) + piece_table_to_string(pt, tmp); + if (strcmp(tmp, "")) return 1; piece_table_destroy(pt); pt = piece_table_create("0123456789"); piece_table_delete(pt, 0, 1); - if (strcmp(piece_table_to_string(pt), "123456789")) + piece_table_to_string(pt, tmp); + if (strcmp(tmp, "123456789")) return 2; piece_table_destroy(pt); pt = piece_table_create("0123456789"); piece_table_delete(pt, 9, 1); - if (strcmp(piece_table_to_string(pt), "012345678")) + piece_table_to_string(pt, tmp); + if (strcmp(tmp, "012345678")) return 3; piece_table_destroy(pt); pt = piece_table_create("0123456789"); piece_table_delete(pt, 7, 1); piece_table_delete(pt, 0, 1); - if (strcmp(piece_table_to_string(pt), "12345689")) + piece_table_to_string(pt, tmp); + if (strcmp(tmp, "12345689")) return 4; piece_table_destroy(pt); -- cgit v1.2.3