Skip to content

Commit fce7397

Browse files
committed
fixed bug in runtime where null pointer was counted as match
1 parent 77c0c16 commit fce7397

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

runtime/Localsearch_Runtime/Viatra/Query/Operations/Extend/NavigateAssociation.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,35 @@ inline NavigateSingleAssociation<SrcType, TrgType, Member, MatchingFrame>::Navig
6969
ExtendOperation<TrgType, std::list<TrgType>, MatchingFrame>(bindMember), _getSrc(getSrc), _navigate(navigate) {
7070
}
7171

72+
/**
73+
* @brief Nullptr checker utility.
74+
*
75+
* This helper struct allows the checking for a nullptr regardless if the type is a pointer. Returns false for
76+
* non pointer values (as they can never be nullptr).
77+
*
78+
* @tparam T Type of the parameter.
79+
*/
80+
template<class T>
81+
struct is_null {
82+
static bool check(const T) {
83+
return false;
84+
}
85+
};
86+
87+
template<class T>
88+
struct is_null<T*> {
89+
static bool check(const T* val) {
90+
return val == nullptr;
91+
}
92+
};
93+
7294
template<class SrcType, class TrgType, class Member, class MatchingFrame>
7395
inline void NavigateSingleAssociation<SrcType, TrgType, Member, MatchingFrame>::on_initialize(MatchingFrame& frame,
7496
const Matcher::ISearchContext&) {
7597
_objectHolder.clear();
76-
_objectHolder.push_back(static_cast<Member*>(frame.*_getSrc)->*_navigate);
98+
auto target = static_cast<Member*>(frame.*_getSrc)->*_navigate;
99+
if(!is_null<decltype(target)>::check(target))
100+
_objectHolder.push_back(target);
77101
ExtendOperation<TrgType, std::list<TrgType>, MatchingFrame>::set_data(_objectHolder.begin(), _objectHolder.end());
78102
}
79103

0 commit comments

Comments
 (0)