btr: Handle zero-sized buffers gracefully.
authorAndre Noll <maan@systemlinux.org>
Sun, 23 Dec 2012 22:58:17 +0000 (23:58 +0100)
committerAndre Noll <maan@systemlinux.org>
Sun, 10 Mar 2013 10:51:19 +0000 (11:51 +0100)
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

index 1c4e046ad8f2aa478bcd4eaf5d94171f0224fd63..cc2bb511696f2e65240a17bbc4962b20c9f0930b 100644 (file)
@@ -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);