Skip to content

Commit

Permalink
Refactor: make the read function simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
gnuser authored and furszy committed Sep 26, 2020
1 parent 585c9fe commit 8345a87
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/streams.h
Expand Up @@ -224,16 +224,15 @@ class CBaseDataStream

// Read from the beginning of the buffer
unsigned int nReadPosNext = nReadPos + nSize;
if (nReadPosNext >= vch.size()) {
if (nReadPosNext > vch.size()) {
throw std::ios_base::failure("CBaseDataStream::read() : end of data");
}
memcpy(pch, &vch[nReadPos], nSize);
if (nReadPosNext > vch.size()) {
throw std::ios_base::failure("CDataStream::read(): end of data");
}
memcpy(pch, &vch[nReadPos], nSize);
if (nReadPosNext == vch.size()) {
nReadPos = 0;
vch.clear();
return;
}
memcpy(pch, &vch[nReadPos], nSize);
nReadPos = nReadPosNext;
}

Expand Down

0 comments on commit 8345a87

Please sign in to comment.