Skip to content

Commit

Permalink
Merge bitcoin#11221: Refactor: simpler read
Browse files Browse the repository at this point in the history
9db9d62 Refactor: make the read function simpler (gnuser)

Pull request description:

Tree-SHA512: 5a80cc1b841488323d421e6a40b245d149cab1988247aed6cc7468dcc042d3df15b6711f25e40ff16e03ac21de36adbaa1d8da61ccdb94f97c8b70c24a5eedc5
  • Loading branch information
laanwj authored and PastaPastaPasta committed Feb 9, 2020
1 parent 304f012 commit 2a018f8
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/streams.h
Expand Up @@ -302,18 +302,16 @@ class CDataStream

// 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("CDataStream::read(): end of data");
}
memcpy(pch, &vch[nReadPos], nSize);
if (nReadPosNext == vch.size())
{
if (nReadPosNext > vch.size())
{
throw std::ios_base::failure("CDataStream::read(): end of data");
}
memcpy(pch, &vch[nReadPos], nSize);
nReadPos = 0;
vch.clear();
return;
}
memcpy(pch, &vch[nReadPos], nSize);
nReadPos = nReadPosNext;
}

Expand Down

0 comments on commit 2a018f8

Please sign in to comment.