From 6a7f2b1e141f17bdc66c4eb9f43e1f115679943f Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Tue, 2 Mar 2010 07:10:00 +0100 Subject: [PATCH] btr: Fix a nasty thinko in merge_input_pool(). We must take into account the number of bytes already consumed from the wrap buffer. Otherwise, we might end up not merging as much as we must, which may cause errors in the child nodes. This bug was quite hard to hit, but it did bite the aac decoder reliably when used in audiod with UDP + FEC. --- buffer_tree.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/buffer_tree.c b/buffer_tree.c index 9be53201..907bd812 100644 --- a/buffer_tree.c +++ b/buffer_tree.c @@ -854,7 +854,7 @@ static void merge_input_pool(struct btr_node *btrn, size_t dest_size) struct btr_buffer_reference *br, *wbr = NULL; int num_refs; /* including wrap buffer */ char *buf, *buf1 = NULL, *buf2 = NULL; - size_t sz, sz1 = 0, sz2 = 0; + size_t sz, sz1 = 0, sz2 = 0, wb_consumed = 0; br = get_first_input_br(btrn); if (!br || br_available_bytes(br) >= dest_size) @@ -871,6 +871,7 @@ static void merge_input_pool(struct btr_node *btrn, size_t dest_size) wbr = br; if (sz >= dest_size) return; + wb_consumed = br->consumed; continue; } if (!buf1) { @@ -890,7 +891,7 @@ static void merge_input_pool(struct btr_node *btrn, size_t dest_size) assert(buf2 + sz2 == buf); sz2 += sz; next: - if (sz1 + sz2 >= dest_size) + if (sz1 + sz2 >= dest_size + wb_consumed) break; } if (!buf2) /* nothing to do */ -- 2.39.5