Skip to content

Commit e23cef0

Browse files
sipaluke-jr
authored andcommitted
Fix some empty vector references
streams.h has some methods that can be tricked into dereferencing null pointers or end() iterators. Fix this. Github-Pull: #10250 Rebased-From: f478d98
1 parent a40d69e commit e23cef0

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)