diff options
author | Pierre Ossman <ossman@cendio.se> | 2019-09-23 11:00:17 +0200 |
---|---|---|
committer | Pierre Ossman <ossman@cendio.se> | 2019-11-15 11:55:05 +0100 |
commit | 0943c006c7d900dfc0281639e992791d6c567438 (patch) | |
tree | 9393960c3d86df32f6186a6feeb4fecfec376699 /common/rdr/MemOutStream.h | |
parent | 4ff58f0acaeb566b79ae12cf013b376eaaaab834 (diff) | |
download | tigervnc-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/MemOutStream.h')
-rw-r--r-- | common/rdr/MemOutStream.h | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/common/rdr/MemOutStream.h b/common/rdr/MemOutStream.h index 3b17e555..4a815b30 100644 --- a/common/rdr/MemOutStream.h +++ b/common/rdr/MemOutStream.h @@ -40,16 +40,16 @@ namespace rdr { delete [] start; } - void writeBytes(const void* data, int length) { + void writeBytes(const void* data, size_t length) { check(length); memcpy(ptr, data, length); ptr += length; } - int length() { return ptr - start; } + size_t length() { return ptr - start; } void clear() { ptr = start; }; void clearAndZero() { memset(start, 0, ptr-start); clear(); } - void reposition(int pos) { ptr = start + pos; } + void reposition(size_t pos) { ptr = start + pos; } // data() returns a pointer to the buffer. @@ -60,9 +60,9 @@ namespace rdr { // overrun() either doubles the buffer or adds enough space for nItems of // size itemSize bytes. - int overrun(int itemSize, int nItems) { - int len = ptr - start + itemSize * nItems; - if (len < (end - start) * 2) + size_t overrun(size_t itemSize, size_t nItems) { + size_t len = ptr - start + itemSize * nItems; + if (len < (size_t)(end - start) * 2) len = (end - start) * 2; U8* newStart = new U8[len]; |