Skip to content

Commit b2c9f7d

Browse files
authored
[clang-tidy] Ensure nullable variable is not accessed without validity test (#90173)
1 parent c229f76 commit b2c9f7d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

clang-tools-extra/clang-tidy/readability/AvoidReturnWithVoidValueCheck.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,11 @@ void AvoidReturnWithVoidValueCheck::check(
6464
<< BraceInsertionHints.closingBraceFixIt();
6565
}
6666
Diag << FixItHint::CreateRemoval(VoidReturn->getReturnLoc());
67-
if (!Result.Nodes.getNodeAs<FunctionDecl>("function_parent") ||
68-
SurroundingBlock->body_back() != VoidReturn)
67+
const auto *FunctionParent =
68+
Result.Nodes.getNodeAs<FunctionDecl>("function_parent");
69+
if (!FunctionParent ||
70+
(SurroundingBlock && SurroundingBlock->body_back() != VoidReturn))
71+
// If this is not the last statement in a function body, we add a `return`.
6972
Diag << FixItHint::CreateInsertion(SemicolonPos.getLocWithOffset(1),
7073
" return;", true);
7174
}

0 commit comments

Comments
 (0)