Skip to content

Commit

Permalink
iox-#1394 Add null checks in storable_function
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Killat <[email protected]>
  • Loading branch information
MatthiasKillat committed Oct 18, 2022
1 parent 6c7ae7f commit 8f3d4de
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ inline storable_function<Capacity, signature<ReturnType, Args...>>::~storable_fu
template <uint64_t Capacity, typename ReturnType, typename... Args>
inline ReturnType storable_function<Capacity, signature<ReturnType, Args...>>::operator()(Args... args) const noexcept
{
cxx::Expects(m_callable != nullptr); // should not happen unless incorrectly used after move
// AXIVION Next Construct AutosarC++19_03-M0.3.1: m_invoker is initialized in ctor or assignment,
// can only be nullptr if this was moved from (calling operator() is illegal in this case)
return m_invoker(m_callable, std::forward<Args>(args)...);
Expand Down Expand Up @@ -198,6 +199,7 @@ inline void storable_function<Capacity, signature<ReturnType, Args...>>::copy(co

// AXIVION Next Construct AutosarC++19_03-M5.2.8: type erasure - conversion to compatible type
const auto obj = static_cast<CallableType*>(src.m_callable);
cxx::Expects(obj != nullptr); // should not happen unless src is incorrectly used after move

// AXIVION Next Construct AutosarC++19_03-A5.3.2: obj is guaranteed not to be
// nullptr unless src was invalidated by move (illegal use of src)
Expand All @@ -221,6 +223,7 @@ inline void storable_function<Capacity, signature<ReturnType, Args...>>::move(st

// AXIVION Next Construct AutosarC++19_03-M5.2.8: type erasure - conversion to compatible type
const auto obj = static_cast<CallableType*>(src.m_callable);
cxx::Expects(obj != nullptr); // should not happen unless src is incorrectly used after move

// AXIVION Next Construct AutosarC++19_03-A5.3.2: obj is guaranteed not to be nullptr
// unless src was invalidated by move (illegal use of src)
Expand Down

0 comments on commit 8f3d4de

Please sign in to comment.