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

@@ -75,7 +75,7 @@ TLSOutStream::~TLSOutStream()
delete [] start;
}
int TLSOutStream::length()
size_t TLSOutStream::length()
{
return offset + ptr - start;
}
@@ -84,7 +84,7 @@ void TLSOutStream::flush()
{
U8* sentUpTo = start;
while (sentUpTo < ptr) {
int n = writeTLS(sentUpTo, ptr - sentUpTo);
size_t n = writeTLS(sentUpTo, ptr - sentUpTo);
sentUpTo += n;
offset += n;
}
@@ -93,20 +93,20 @@ void TLSOutStream::flush()
out->flush();
}
int TLSOutStream::overrun(int itemSize, int nItems)
size_t TLSOutStream::overrun(size_t itemSize, size_t nItems)
{
if (itemSize > bufSize)
throw Exception("TLSOutStream overrun: max itemSize exceeded");
flush();
if (itemSize * nItems > end - ptr)
if (itemSize * nItems > (size_t)(end - ptr))
nItems = (end - ptr) / itemSize;
return nItems;
}
int TLSOutStream::writeTLS(const U8* data, int length)
size_t TLSOutStream::writeTLS(const U8* data, size_t length)
{
int n;