Skip to content

Commit 1428f30

Browse files
committed
Merge #10250: Fix some empty vector references
f478d98 Fix some empty vector references (Pieter Wuille) Tree-SHA512: a22022b9060cd39f8d349e8dd24490614c0028eae2fbc7186d0d26b1d47529049b2daee41f093c0722130274a0b6f7f8671c2295c8cb4a97028771eaff080734
2 parents 5352e5e + f478d98 commit 1428f30

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/streams.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ class CDataStream
248248

249249
void insert(iterator it, std::vector<char>::const_iterator first, std::vector<char>::const_iterator last)
250250
{
251-
assert(last - first >= 0);
251+
if (last == first) return;
252+
assert(last - first > 0);
252253
if (it == vch.begin() + nReadPos && (unsigned int)(last - first) <= nReadPos)
253254
{
254255
// special case for inserting at the front when there's room
@@ -261,7 +262,8 @@ class CDataStream
261262

262263
void insert(iterator it, const char* first, const char* last)
263264
{
264-
assert(last - first >= 0);
265+
if (last == first) return;
266+
assert(last - first > 0);
265267
if (it == vch.begin() + nReadPos && (unsigned int)(last - first) <= nReadPos)
266268
{
267269
// special case for inserting at the front when there's room
@@ -339,6 +341,8 @@ class CDataStream
339341

340342
void read(char* pch, size_t nSize)
341343
{
344+
if (nSize == 0) return;
345+
342346
// Read from the beginning of the buffer
343347
unsigned int nReadPosNext = nReadPos + nSize;
344348
if (nReadPosNext >= vch.size())

0 commit comments

Comments
 (0)