Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6566:1f98c63aaaa3 HEAD
Fixes
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 20 Oct 2007 20:32:43 +0300 |
parents | b39233d16d0f |
children | b8442b2e3c04 |
files | src/lib/istream-concat.c |
diffstat | 1 files changed, 17 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/istream-concat.c Sat Oct 20 20:20:43 2007 +0300 +++ b/src/lib/istream-concat.c Sat Oct 20 20:32:43 2007 +0300 @@ -54,14 +54,21 @@ cstream->cur_idx++; cstream->cur_input = cstream->input[cstream->cur_idx]; + i_stream_seek(cstream->cur_input, 0); - if (cstream->istream.pos == cstream->istream.skip) + if (cstream->istream.pos == cstream->istream.skip) { + i_assert(cstream->prev_size == 0); + cstream->istream.skip = 0; + cstream->istream.pos = 0; return; + } /* we need to keep the current data */ data = cstream->istream.buffer + cstream->istream.skip; data_size = cstream->istream.pos - cstream->istream.skip; + cstream->istream.skip = cstream->istream.pos = 0; + /* we already verified that the data size is less than the maximum buffer size */ if (!i_stream_get_buffer_space(&cstream->istream, data_size, &size)) @@ -70,6 +77,7 @@ cstream->prev_size = data_size; memcpy(cstream->istream.w_buffer, data, data_size); + cstream->istream.pos = data_size; } static ssize_t i_stream_concat_read(struct istream_private *stream) @@ -124,8 +132,7 @@ return -2; i_stream_concat_read_next(cstream); - last_stream = - cstream->input[cstream->cur_idx+1] == NULL; + return i_stream_concat_read(stream); } stream->istream.eof = cstream->cur_input->eof && last_stream; @@ -139,9 +146,13 @@ } else { if (!i_stream_get_buffer_space(stream, pos, &size)) return -2; - memcpy(stream->w_buffer + stream->pos, data, I_MIN(size, pos)); + + if (pos > size) + pos = size; + memcpy(stream->w_buffer + stream->pos, data, pos); } + pos += cstream->prev_size; ret = pos > stream->pos ? (ssize_t)(pos - stream->pos) : (ret == 0 ? 0 : -1); stream->pos = pos; @@ -188,6 +199,7 @@ stream->istream.stream_errno = 0; stream->istream.v_offset = v_offset; stream->skip = stream->pos = 0; + cstream->prev_size = 0; cstream->cur_idx = find_v_offset(cstream, &v_offset); if (cstream->cur_idx == (unsigned int)-1) { @@ -242,6 +254,7 @@ memcpy(cstream->input, input, sizeof(*input) * count); cstream->cur_input = cstream->input[0]; + i_stream_seek(cstream->cur_input, 0); cstream->istream.iostream.close = i_stream_concat_close; cstream->istream.iostream.destroy = i_stream_concat_destroy;