aboutsummaryrefslogtreecommitdiffstats
path: root/common/rdr/RandomStream.cxx
diff options
context:
space:
mode:
authorPierre Ossman <ossman@cendio.se>2022-08-23 17:09:40 +0200
committerPierre Ossman <ossman@cendio.se>2022-08-25 11:06:33 +0200
commit0ae1557ed9a7f8b46b6d7e2feaf2fad4cc2c3b3d (patch)
treebc0fdcf38944b9aba09198f5e7d0967ab056ef8e /common/rdr/RandomStream.cxx
parent62965aa1cd7cd126c7ed505f07430a7194cb3e0f (diff)
downloadtigervnc-0ae1557ed9a7f8b46b6d7e2feaf2fad4cc2c3b3d.tar.gz
tigervnc-0ae1557ed9a7f8b46b6d7e2feaf2fad4cc2c3b3d.zip
Make BufferedInStream allocation more available
Allow subclasses to call it, instead of it being strictly internal. This is useful when a subclass can only provide data in minimum sized chunks.
Diffstat (limited to 'common/rdr/RandomStream.cxx')
-rw-r--r--common/rdr/RandomStream.cxx10
1 files changed, 5 insertions, 5 deletions
diff --git a/common/rdr/RandomStream.cxx b/common/rdr/RandomStream.cxx
index ec367212..c9be704c 100644
--- a/common/rdr/RandomStream.cxx
+++ b/common/rdr/RandomStream.cxx
@@ -83,17 +83,17 @@ RandomStream::~RandomStream() {
#endif
}
-bool RandomStream::fillBuffer(size_t maxSize) {
+bool RandomStream::fillBuffer() {
#ifdef RFB_HAVE_WINCRYPT
if (provider) {
- if (!CryptGenRandom(provider, maxSize, (U8*)end))
+ if (!CryptGenRandom(provider, availSpace(), (U8*)end))
throw rdr::SystemException("unable to CryptGenRandom", GetLastError());
- end += maxSize;
+ end += availSpace();
} else {
#else
#ifndef WIN32
if (fp) {
- size_t n = fread((U8*)end, 1, maxSize, fp);
+ size_t n = fread((U8*)end, 1, availSpace(), fp);
if (n <= 0)
throw rdr::SystemException("reading /dev/urandom or /dev/random failed",
errno);
@@ -103,7 +103,7 @@ bool RandomStream::fillBuffer(size_t maxSize) {
{
#endif
#endif
- for (size_t i=0; i<maxSize; i++)
+ for (size_t i=availSpace(); i>0; i--)
*(U8*)end++ = (int) (256.0*rand()/(RAND_MAX+1.0));
}