aboutsummaryrefslogtreecommitdiffstats
path: root/common/rdr/FdInStream.cxx
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2019-09-23 11:00:17 +0200
committerPierre Ossman <ossman@cendio.se>2019-11-15 11:55:05 +0100
commit0943c006c7d900dfc0281639e992791d6c567438 (patch)
tree9393960c3d86df32f6186a6feeb4fecfec376699 /common/rdr/FdInStream.cxx
parent4ff58f0acaeb566b79ae12cf013b376eaaaab834 (diff)
downloadtigervnc-0943c006c7d900dfc0281639e992791d6c567438.tar.gz
tigervnc-0943c006c7d900dfc0281639e992791d6c567438.zip
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.
Diffstat (limited to 'common/rdr/FdInStream.cxx')
-rw-r--r--common/rdr/FdInStream.cxx20
1 files changed, 10 insertions, 10 deletions
diff --git a/common/rdr/FdInStream.cxx b/common/rdr/FdInStream.cxx
index 1b9a322a..9e84ab7a 100644
--- a/common/rdr/FdInStream.cxx
+++ b/common/rdr/FdInStream.cxx
@@ -56,7 +56,7 @@ using namespace rdr;
enum { DEFAULT_BUF_SIZE = 8192,
MIN_BULK_SIZE = 1024 };
-FdInStream::FdInStream(int fd_, int timeoutms_, int bufSize_,
+FdInStream::FdInStream(int fd_, int timeoutms_, size_t bufSize_,
bool closeWhenDone_)
: fd(fd_), closeWhenDone(closeWhenDone_),
timeoutms(timeoutms_), blockCallback(0),
@@ -67,7 +67,7 @@ FdInStream::FdInStream(int fd_, int timeoutms_, int bufSize_,
}
FdInStream::FdInStream(int fd_, FdInStreamBlockCallback* blockCallback_,
- int bufSize_)
+ size_t bufSize_)
: fd(fd_), timeoutms(0), blockCallback(blockCallback_),
timing(false), timeWaitedIn100us(5), timedKbits(0),
bufSize(bufSize_ ? bufSize_ : DEFAULT_BUF_SIZE), offset(0)
@@ -92,12 +92,12 @@ void FdInStream::setBlockCallback(FdInStreamBlockCallback* blockCallback_)
timeoutms = 0;
}
-int FdInStream::pos()
+size_t FdInStream::pos()
{
return offset + ptr - start;
}
-void FdInStream::readBytes(void* data, int length)
+void FdInStream::readBytes(void* data, size_t length)
{
if (length < MIN_BULK_SIZE) {
InStream::readBytes(data, length);
@@ -106,7 +106,7 @@ void FdInStream::readBytes(void* data, int length)
U8* dataPtr = (U8*)data;
- int n = end - ptr;
+ size_t n = end - ptr;
if (n > length) n = length;
memcpy(dataPtr, ptr, n);
@@ -123,7 +123,7 @@ void FdInStream::readBytes(void* data, int length)
}
-int FdInStream::overrun(int itemSize, int nItems, bool wait)
+size_t FdInStream::overrun(size_t itemSize, size_t nItems, bool wait)
{
if (itemSize > bufSize)
throw Exception("FdInStream overrun: max itemSize exceeded");
@@ -135,7 +135,7 @@ int FdInStream::overrun(int itemSize, int nItems, bool wait)
end -= ptr - start;
ptr = start;
- int bytes_to_read;
+ size_t bytes_to_read;
while (end < start + itemSize) {
bytes_to_read = start + bufSize - end;
if (!timing) {
@@ -147,12 +147,12 @@ int FdInStream::overrun(int itemSize, int nItems, bool wait)
// bytes is ineffecient.
bytes_to_read = vncmin(bytes_to_read, vncmax(itemSize*nItems, 8));
}
- int n = readWithTimeoutOrCallback((U8*)end, bytes_to_read, wait);
+ size_t n = readWithTimeoutOrCallback((U8*)end, bytes_to_read, wait);
if (n == 0) return 0;
end += n;
}
- if (itemSize * nItems > end - ptr)
+ if (itemSize * nItems > (size_t)(end - ptr))
nItems = (end - ptr) / itemSize;
return nItems;
@@ -171,7 +171,7 @@ int FdInStream::overrun(int itemSize, int nItems, bool wait)
// returning EINTR.
//
-int FdInStream::readWithTimeoutOrCallback(void* buf, int len, bool wait)
+size_t FdInStream::readWithTimeoutOrCallback(void* buf, size_t len, bool wait)
{
struct timeval before, after;
if (timing)