Skip to content

Commit 0dec4cc

Browse files
committed
Merge #11221: Refactor: simpler read
9db9d62 Refactor: make the read function simpler (gnuser) Pull request description: Tree-SHA512: 5a80cc1b841488323d421e6a40b245d149cab1988247aed6cc7468dcc042d3df15b6711f25e40ff16e03ac21de36adbaa1d8da61ccdb94f97c8b70c24a5eedc5
2 parents b5f9f02 + 9db9d62 commit 0dec4cc

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/streams.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -345,18 +345,16 @@ class CDataStream
345345

346346
// Read from the beginning of the buffer
347347
unsigned int nReadPosNext = nReadPos + nSize;
348-
if (nReadPosNext >= vch.size())
348+
if (nReadPosNext > vch.size()) {
349+
throw std::ios_base::failure("CDataStream::read(): end of data");
350+
}
351+
memcpy(pch, &vch[nReadPos], nSize);
352+
if (nReadPosNext == vch.size())
349353
{
350-
if (nReadPosNext > vch.size())
351-
{
352-
throw std::ios_base::failure("CDataStream::read(): end of data");
353-
}
354-
memcpy(pch, &vch[nReadPos], nSize);
355354
nReadPos = 0;
356355
vch.clear();
357356
return;
358357
}
359-
memcpy(pch, &vch[nReadPos], nSize);
360358
nReadPos = nReadPosNext;
361359
}
362360

0 commit comments

Comments
 (0)