From f2a68e4b852931ca1d47bb0ebf8205c6a0af6cf5 Mon Sep 17 00:00:00 2001 From: gibbed Date: Mon, 28 Jun 2021 12:33:05 -0500 Subject: [PATCH] [Base] ByteStream assert cleanup. --- src/xenia/base/byte_stream.cc | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/xenia/base/byte_stream.cc b/src/xenia/base/byte_stream.cc index cdd69a1ba..3775cfc91 100644 --- a/src/xenia/base/byte_stream.cc +++ b/src/xenia/base/byte_stream.cc @@ -20,18 +20,19 @@ ByteStream::ByteStream(uint8_t* data, size_t data_length, size_t offset) ByteStream::~ByteStream() = default; -void ByteStream::Advance(size_t num_bytes) { offset_ += num_bytes; } +void ByteStream::Advance(size_t num_bytes) { + assert_true(offset_ + num_bytes <= data_length_); + offset_ += num_bytes; +} void ByteStream::Read(uint8_t* buf, size_t len) { - assert_true(offset_ < data_length_); - + assert_true(offset_ + len <= data_length_); std::memcpy(buf, data_ + offset_, len); Advance(len); } void ByteStream::Write(const uint8_t* buf, size_t len) { - assert_true(offset_ < data_length_); - + assert_true(offset_ + len <= data_length_); std::memcpy(data_ + offset_, buf, len); Advance(len); } @@ -41,7 +42,6 @@ std::string ByteStream::Read() { std::string str; uint32_t len = Read(); str.resize(len); - Read(reinterpret_cast(&str[0]), len); return str; } @@ -49,9 +49,8 @@ std::string ByteStream::Read() { template <> std::u16string ByteStream::Read() { std::u16string str; - uint32_t len = Read(); + size_t len = Read(); str.resize(len); - Read(reinterpret_cast(&str[0]), len * 2); return str; }