aboutsummaryrefslogtreecommitdiffstats
path: root/common/rdr/RandomStream.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/RandomStream.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/RandomStream.cxx')
-rw-r--r--common/rdr/RandomStream.cxx14
1 files changed, 7 insertions, 7 deletions
diff --git a/common/rdr/RandomStream.cxx b/common/rdr/RandomStream.cxx
index e22da3d0..d5f1cc85 100644
--- a/common/rdr/RandomStream.cxx
+++ b/common/rdr/RandomStream.cxx
@@ -35,7 +35,7 @@ static rfb::LogWriter vlog("RandomStream");
using namespace rdr;
-const int DEFAULT_BUF_LEN = 256;
+const size_t DEFAULT_BUF_LEN = 256;
unsigned int RandomStream::seed;
@@ -86,11 +86,11 @@ RandomStream::~RandomStream() {
#endif
}
-int RandomStream::pos() {
+size_t RandomStream::pos() {
return offset + ptr - start;
}
-int RandomStream::overrun(int itemSize, int nItems, bool wait) {
+size_t RandomStream::overrun(size_t itemSize, size_t nItems, bool wait) {
if (itemSize > DEFAULT_BUF_LEN)
throw Exception("RandomStream overrun: max itemSize exceeded");
@@ -101,7 +101,7 @@ int RandomStream::overrun(int itemSize, int nItems, bool wait) {
offset += ptr - start;
ptr = start;
- int length = start + DEFAULT_BUF_LEN - end;
+ size_t length = start + DEFAULT_BUF_LEN - end;
#ifdef RFB_HAVE_WINCRYPT
if (provider) {
@@ -112,7 +112,7 @@ int RandomStream::overrun(int itemSize, int nItems, bool wait) {
#else
#ifndef WIN32
if (fp) {
- int n = fread((U8*)end, length, 1, fp);
+ size_t n = fread((U8*)end, length, 1, fp);
if (n != 1)
throw rdr::SystemException("reading /dev/urandom or /dev/random failed",
errno);
@@ -122,11 +122,11 @@ int RandomStream::overrun(int itemSize, int nItems, bool wait) {
{
#endif
#endif
- for (int i=0; i<length; i++)
+ for (size_t i=0; i<length; i++)
*(U8*)end++ = (int) (256.0*rand()/(RAND_MAX+1.0));
}
- if (itemSize * nItems > end - ptr)
+ if (itemSize * nItems > (size_t)(end - ptr))
nItems = (end - ptr) / itemSize;
return nItems;