From dd69230f197ef58541dd7e81bf5d8b82979025d5 Mon Sep 17 00:00:00 2001 From: Glen Fraser Date: Fri, 4 Sep 2020 11:27:52 +0200 Subject: [PATCH] Fix issues with Function_Params constructors (array and vector args) - code (on MSVC) was asserting due to trying to dereference invalid pointers (dereferencing the end iterator, even if only to get its address!). - when a Function_Params is constructed with an empty vector, you can't return the address of the vec.front() -- instead we use nullptr for the m_begin and m_end pointers. --- include/chaiscript/dispatchkit/function_params.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/chaiscript/dispatchkit/function_params.hpp b/include/chaiscript/dispatchkit/function_params.hpp index c8afaaf89..249c41a76 100644 --- a/include/chaiscript/dispatchkit/function_params.hpp +++ b/include/chaiscript/dispatchkit/function_params.hpp @@ -30,13 +30,19 @@ namespace chaiscript { } explicit Function_Params(const std::vector &vec) - : m_begin(&vec.front()), m_end(&vec.front() + vec.size()) + : m_begin(vec.empty() ? nullptr : &vec.front()), m_end(vec.empty() ? nullptr : &vec.front() + vec.size()) { } template constexpr explicit Function_Params(const std::array &a) - : m_begin(&*std::begin(a)), m_end(&*std::end(a)) + : m_begin(&a.front()), m_end(&a.front() + Size) + { + } + + template<> + constexpr explicit Function_Params(const std::array &a) + : m_begin(nullptr), m_end(nullptr) { }