From 8345a87de991805733ec2786b7ae894c8516e1f6 Mon Sep 17 00:00:00 2001 From: gnuser Date: Sat, 2 Sep 2017 22:41:25 -0700 Subject: [PATCH] Refactor: make the read function simpler --- src/streams.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/streams.h b/src/streams.h index 35866dea330cf..3e2c1f653d255 100644 --- a/src/streams.h +++ b/src/streams.h @@ -224,16 +224,15 @@ class CBaseDataStream // 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("CBaseDataStream::read() : end of data"); - } - memcpy(pch, &vch[nReadPos], nSize); + if (nReadPosNext > vch.size()) { + throw std::ios_base::failure("CDataStream::read(): end of data"); + } + memcpy(pch, &vch[nReadPos], nSize); + if (nReadPosNext == vch.size()) { nReadPos = 0; vch.clear(); return; } - memcpy(pch, &vch[nReadPos], nSize); nReadPos = nReadPosNext; }