From 07fdaa7973c1b97ded3ebd200ef845728547f94e Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 23 Dec 2012 23:58:17 +0100 Subject: [PATCH] btr: Handle zero-sized buffers gracefully. There is no need to abort on the attempt to add a zero sized buffer. Let's be gentle and make this condition a noop rather than a fatal error. --- buffer_tree.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/buffer_tree.c b/buffer_tree.c index 1c4e046a..cc2bb511 100644 --- a/buffer_tree.c +++ b/buffer_tree.c @@ -386,7 +386,8 @@ void btr_add_output(char *buf, size_t size, struct btr_node *btrn) { struct btr_buffer *btrb; - assert(size != 0); + if (size == 0) + return; if (list_empty(&btrn->children)) { free(buf); return; @@ -415,7 +416,8 @@ void btr_add_output_dont_free(const char *buf, size_t size, struct btr_node *btr { struct btr_buffer *btrb; - assert(size != 0); + if (size == 0) + return; if (list_empty(&btrn->children)) return; btrb = new_btrb((char *)buf, size); @@ -442,7 +444,8 @@ void btr_add_output_pool(struct btr_pool *btrp, size_t size, char *buf; size_t avail; - assert(size != 0); + if (size == 0) + return; if (list_empty(&btrn->children)) return; avail = btr_pool_get_buffer(btrp, &buf); -- 2.39.5