Fix bytebuffer

This commit is contained in:
Maurice Heumann 2023-04-04 18:23:10 +02:00
parent 27ab6193e5
commit 077167e81b
2 changed files with 8 additions and 3 deletions

View File

@ -1,7 +1,6 @@
#include "byte_buffer.hpp"
#include <cstring>
#include <stdexcept>
namespace utils
{

View File

@ -2,6 +2,7 @@
#include <string>
#include <vector>
#include <stdexcept>
namespace utils
{
@ -73,8 +74,13 @@ namespace utils
std::vector<T> read_vector()
{
std::vector<T> result{};
result.resize(read<uint32_t>());
read(result.data(), result.size() * sizeof(T));
const auto size = read<uint32_t>();
if (offset_ + size > buffer_.size())
{
throw std::runtime_error("Out of bounds read from byte buffer");
}
read(result.data(), size);
return result;
}