Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing BlockStream::BlockQueuePeekBytes #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 14 additions & 6 deletions libdash/libdash/source/helpers/BlockStream.cpp
Expand Up @@ -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++;
Expand Down Expand Up @@ -287,4 +295,4 @@ BlockStream* BlockStream::GetBlocks (uint64_t len)
}

return blocks;
}
}