mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
Refactor: make the read function simpler
This commit is contained in:
@@ -345,18 +345,16 @@ public:
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user