Use size_t for lengths in stream objects

Provides safety against them accidentally becoming negative because
of bugs in the calculations.

Also does the same to CharArray and friends as they were strongly
connection to the stream objects.
This commit is contained in:
Pierre Ossman
2019-09-23 11:00:17 +02:00
committed by Lauri Kasanen
parent 346fccb96c
commit 259f1055cb
31 changed files with 180 additions and 178 deletions

View File

@@ -30,7 +30,7 @@ using namespace rdr;
enum { DEFAULT_BUF_SIZE = 16384 };
ZlibOutStream::ZlibOutStream(OutStream* os, int bufSize_, int compressLevel)
ZlibOutStream::ZlibOutStream(OutStream* os, size_t bufSize_, int compressLevel)
: underlying(os), compressionLevel(compressLevel), newLevel(compressLevel),
bufSize(bufSize_ ? bufSize_ : DEFAULT_BUF_SIZE), offset(0)
{
@@ -72,7 +72,7 @@ void ZlibOutStream::setCompressionLevel(int level)
newLevel = level;
}
int ZlibOutStream::length()
size_t ZlibOutStream::length()
{
return offset + ptr - start;
}
@@ -95,7 +95,7 @@ void ZlibOutStream::flush()
ptr = start;
}
int ZlibOutStream::overrun(int itemSize, int nItems)
size_t ZlibOutStream::overrun(size_t itemSize, size_t nItems)
{
#ifdef ZLIBOUT_DEBUG
fprintf(stderr,"zos overrun\n");
@@ -106,7 +106,7 @@ int ZlibOutStream::overrun(int itemSize, int nItems)
checkCompressionLevel();
while (end - ptr < itemSize) {
while ((size_t)(end - ptr) < itemSize) {
zs->next_in = start;
zs->avail_in = ptr - start;
@@ -127,7 +127,7 @@ int ZlibOutStream::overrun(int itemSize, int nItems)
}
}
if (itemSize * nItems > end - ptr)
if (itemSize * nItems > (size_t)(end - ptr))
nItems = (end - ptr) / itemSize;
return nItems;