Skip to content

Commit

Permalink
Fix issues with Function_Params constructors (array and vector args)
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
totalgee committed Sep 4, 2020
1 parent 27072a7 commit dd69230
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions include/chaiscript/dispatchkit/function_params.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@ namespace chaiscript {
}

explicit Function_Params(const std::vector<Boxed_Value> &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<size_t Size>
constexpr explicit Function_Params(const std::array<Boxed_Value, Size> &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<Boxed_Value, size_t{0}> &a)
: m_begin(nullptr), m_end(nullptr)
{
}

Expand Down

0 comments on commit dd69230

Please sign in to comment.