Skip to content

Commit 9db9d62

Browse files
committed
Refactor: make the read function simpler
1 parent acb1153 commit 9db9d62

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)