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

@@ -48,7 +48,7 @@ void FileInStream::reset(void) {
ptr = end = b;
}
int FileInStream::pos()
size_t FileInStream::pos()
{
if (!file)
throw Exception("File is not open");
@@ -56,9 +56,9 @@ int FileInStream::pos()
return ftell(file) + ptr - b;
}
int FileInStream::overrun(int itemSize, int nItems, bool wait)
size_t FileInStream::overrun(size_t itemSize, size_t nItems, bool wait)
{
if (itemSize > (int)sizeof(b))
if (itemSize > sizeof(b))
throw Exception("FileInStream overrun: max itemSize exceeded");
if (end - ptr != 0)
@@ -80,7 +80,7 @@ int FileInStream::overrun(int itemSize, int nItems, bool wait)
end += b + sizeof(b) - end;
}
if (itemSize * nItems > end - ptr)
if (itemSize * nItems > (size_t)(end - ptr))
nItems = (end - ptr) / itemSize;
return nItems;