From 0943c006c7d900dfc0281639e992791d6c567438 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 23 Sep 2019 11:00:17 +0200 Subject: 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. --- common/rdr/MemOutStream.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'common/rdr/MemOutStream.h') 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]; -- cgit v1.2.3