diff options
| author | gnuser <[email protected]> | 2017-09-02 22:41:25 -0700 |
|---|---|---|
| committer | gnuser <[email protected]> | 2017-09-02 22:41:25 -0700 |
| commit | 9db9d6215f48167c0d1f441527796a14bc223ff7 (patch) | |
| tree | a39174b1bd79151da14d42399c47efc2ac0e10e9 /src | |
| parent | Merge #10659: [qa] blockchain: Pass on closed connection during generate call (diff) | |
| download | discoin-9db9d6215f48167c0d1f441527796a14bc223ff7.tar.xz discoin-9db9d6215f48167c0d1f441527796a14bc223ff7.zip | |
Refactor: make the read function simpler
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 8dc5a19ea..df1cd50c9 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; } |