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.
This commit is contained in:
Pierre Ossman
2019-09-23 11:00:17 +02:00
committed by Lauri Kasanen
parent 346fccb96c
commit 259f1055cb
31 changed files with 180 additions and 178 deletions

View File

@@ -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];