aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/tourist/foundation/src/stream.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'thirdparty/tourist/foundation/src/stream.cpp')
-rw-r--r--thirdparty/tourist/foundation/src/stream.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/thirdparty/tourist/foundation/src/stream.cpp b/thirdparty/tourist/foundation/src/stream.cpp
index c560436d3..97d4cb395 100644
--- a/thirdparty/tourist/foundation/src/stream.cpp
+++ b/thirdparty/tourist/foundation/src/stream.cpp
@@ -2,6 +2,8 @@
#include "slab.h"
+#include <stdexcept>
+
//------------------------------------------------------------------------------
BufferStream::BufferStream(Slab* slab, const uint8* ptr, uint32 size)
: _ptr(ptr)
@@ -37,8 +39,11 @@ uint32 BufferStream::get_remaining() const
//------------------------------------------------------------------------------
const uint8* BufferStream::read(uint32 size)
{
+ if (size > _end - _cursor)
+ throw std::runtime_error("BufferStream: read past end of buffer");
+ const uint8* ret = (uint8*)_ptr + _cursor;
_cursor += size;
- return (uint8*)_ptr + _cursor - size;
+ return ret;
}
//------------------------------------------------------------------------------