Skip to content

Commit

Permalink
Avoid null dereference in Visitor::findContext for visitor without co…
Browse files Browse the repository at this point in the history
…ntext

found by clang-tidy
  • Loading branch information
vlstill committed Nov 3, 2023
1 parent bceab95 commit e7859c3
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ir/visitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class Visitor {
template <class T>
inline const T *findContext(const Context *&c) const {
if (!c) c = ctxt;
if (!c) return nullptr;
while ((c = c->parent))
if (auto *rv = dynamic_cast<const T *>(c->node)) return rv;
return nullptr;
Expand All @@ -257,6 +258,7 @@ class Visitor {
template <class T>
inline const T *findOrigCtxt(const Context *&c) const {
if (!c) c = ctxt;
if (!c) return nullptr;
while ((c = c->parent))
if (auto *rv = dynamic_cast<const T *>(c->original)) return rv;
return nullptr;
Expand Down

0 comments on commit e7859c3

Please sign in to comment.