From 9cd317624e09bb8c782b1c5c8023e01876f8afa1 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Mon, 18 Oct 2021 12:28:15 +0100 Subject: [PATCH] Couple of extra safety checks. Signed-off-by: Adrian Conlon --- M6502/HarteTest_6502/cycles_t.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/M6502/HarteTest_6502/cycles_t.cpp b/M6502/HarteTest_6502/cycles_t.cpp index 4c2c31f..b5c834b 100644 --- a/M6502/HarteTest_6502/cycles_t.cpp +++ b/M6502/HarteTest_6502/cycles_t.cpp @@ -6,12 +6,14 @@ cycles_t::cycles_t(size_t reserved) { } void cycles_t::add(const cycle_t& cycle) { + assert(m_cycles.capacity() >= (m_cycles.size() + 1)); m_cycles.push_back(cycle); } #ifdef USE_SIMDJSON_JSON cycles_t::cycles_t(simdjson::dom::array input) { + assert(m_cycles.empty()); m_cycles.reserve(input.size()); for (const auto& entry : input) add(entry); @@ -25,6 +27,7 @@ cycles_t::cycles_t(const boost::json::value& input) : cycles_t(input.as_array()) {} cycles_t::cycles_t(const boost::json::array& input) { + assert(m_cycles.empty()); m_cycles.reserve(input.size()); for (const auto& entry : input) add(entry); @@ -35,6 +38,7 @@ cycles_t::cycles_t(const boost::json::array& input) { #ifdef USE_NLOHMANN_JSON cycles_t::cycles_t(const nlohmann::json& input) { + assert(m_cycles.empty()); m_cycles.reserve(input.size()); for (const auto& entry : input) add(entry); @@ -45,6 +49,7 @@ cycles_t::cycles_t(const nlohmann::json& input) { #ifdef USE_JSONCPP_JSON cycles_t::cycles_t(const Json::Value& input) { + assert(m_cycles.empty()); m_cycles.reserve(input.size()); for (const auto& entry : input) add(entry);