diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2017-11-09 13:15:58 +0100 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2017-11-09 13:16:03 +0100 |
commit | 0dec4cc30044dcabfcedd4a41023280454f6ec71 (patch) | |
tree | 4eedea66464bee11f55e9ca85c2ec1da496c6aba /src | |
parent | b5f9f025fef0c3c38bc4b29f01356dc9b23289fe (diff) | |
parent | 9db9d6215f48167c0d1f441527796a14bc223ff7 (diff) |
Merge #11221: Refactor: simpler read
9db9d62 Refactor: make the read function simpler (gnuser)
Pull request description:
Tree-SHA512: 5a80cc1b841488323d421e6a40b245d149cab1988247aed6cc7468dcc042d3df15b6711f25e40ff16e03ac21de36adbaa1d8da61ccdb94f97c8b70c24a5eedc5
Diffstat (limited to 'src')
-rw-r--r-- | src/streams.h | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/streams.h b/src/streams.h index 9a3badea57..5dbeaac9a5 100644 --- a/src/streams.h +++ b/src/streams.h @@ -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; } |