From 2a018f880756dae7d0d1c941551884116ad01c33 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 9 Nov 2017 13:15:58 +0100 Subject: [PATCH] Merge #11221: Refactor: simpler read 9db9d62 Refactor: make the read function simpler (gnuser) Pull request description: Tree-SHA512: 5a80cc1b841488323d421e6a40b245d149cab1988247aed6cc7468dcc042d3df15b6711f25e40ff16e03ac21de36adbaa1d8da61ccdb94f97c8b70c24a5eedc5 --- src/streams.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/streams.h b/src/streams.h index 77c488adc062d..030f362e188a9 100644 --- a/src/streams.h +++ b/src/streams.h @@ -302,18 +302,16 @@ class CDataStream // 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; }