Skip to content

Commit

Permalink
Fix ub in any (#777)
Browse files Browse the repository at this point in the history
* Fixed undefined behavior in Any::operator==(value)

* Revert "Fixed undefined behavior in Any::operator==(value)"

This reverts commit 3066fe1.

* Fixed undefined behavior in Any::operator==(value)

* removed unnecessary forward declaration.

* Fixed undefined behavior in Any::operator==(value)

* removed unnecessary forward declaration.
  • Loading branch information
carneyweb committed Jan 26, 2023
1 parent bb43780 commit 7cbb41c
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions framework/include/cppmicroservices/Any.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ namespace cppmicroservices
}

template <typename ValueType>
ValueType* any_cast(Any* operand);
ValueType& ref_any_cast(Any& operand);

template <typename ValueType>
ValueType const& ref_any_cast(Any const& operand);

template <class T>
std::ostream&
Expand Down Expand Up @@ -340,7 +343,8 @@ namespace cppmicroservices
{
if (Type() != typeid(ValueType))
return false;
return cppmicroservices::any::detail::compare(*any_cast<ValueType const>(this), val);
ValueType const& my_val = cppmicroservices::ref_any_cast<ValueType>(*this);
return cppmicroservices::any::detail::compare(my_val, val);
}

/**
Expand Down

0 comments on commit 7cbb41c

Please sign in to comment.