diff --git a/libdash/libdash/source/helpers/BlockStream.cpp b/libdash/libdash/source/helpers/BlockStream.cpp index 6716df4d..08debfb7 100644 --- a/libdash/libdash/source/helpers/BlockStream.cpp +++ b/libdash/libdash/source/helpers/BlockStream.cpp @@ -157,15 +157,23 @@ bool BlockStream::BlockQueuePeekBytes (uint8_t *data, uint32_t len while(pos < len) { block = this->blockqueue.at(cnt); - if((offset + len - pos) < (block->len)) + if (offset >= block->len) { - memcpy(data + pos, block->data + offset, len - pos - offset); - return true; + offset-= block->len; } else { - memcpy(data + pos, block->data + offset, block->len - offset); - pos += block->len; + if((offset + len - pos) < (block->len)) + { + memcpy(data + pos, block->data + offset, len - pos - offset); + return true; + } + else + { + memcpy(data + pos, block->data + offset, block->len - offset); + pos += (block->len - offset); + offset = 0; + } } cnt++; @@ -287,4 +295,4 @@ BlockStream* BlockStream::GetBlocks (uint64_t len) } return blocks; -} \ No newline at end of file +}