[NFC] [clang-tidy] Fix potential SA issues. (#170289)

This patch addresses issues identified by the static analyzers, which
appear to be legitimate problems.

`FloatLoopCounterCheck.cpp`: "Dereferencing a pointer that might be
`nullptr` FS when calling `getInc`".
`ProBoundsAvoidUncheckedContainerAccessCheck.cpp`: "Dereferencing a
pointer that might be `nullptr Callee` when calling `getBeginLoc`".
`ExpandModularHeadersPPCallbacks.cpp`: Non-static class member
`CurrentToken.Flags` is not initialized in this constructor nor in any
functions that it calls. (line #101).
This commit is contained in:
Zahira Ammarguellat 2025-12-02 11:38:18 -05:00 committed by GitHub
parent 6984f942bc
commit c6910201cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 3 additions and 2 deletions

View File

@ -137,7 +137,7 @@ private:
std::unique_ptr<Preprocessor> PP;
bool EnteredMainFile = false;
bool StartedLexing = false;
Token CurrentToken;
Token CurrentToken = Token();
};
} // namespace tooling

View File

@ -31,6 +31,7 @@ void FloatLoopCounterCheck::registerMatchers(MatchFinder *Finder) {
void FloatLoopCounterCheck::check(const MatchFinder::MatchResult &Result) {
const auto *FS = Result.Nodes.getNodeAs<ForStmt>("for");
assert(FS && "FS should not be null");
diag(FS->getInc()->getBeginLoc(), "loop induction expression should not have "
"floating-point type")

View File

@ -176,7 +176,7 @@ void ProBoundsAvoidUncheckedContainerAccessCheck::check(
}
} else if (const auto *MCE = dyn_cast<CXXMemberCallExpr>(MatchedExpr)) {
// Case: a.operator[](i) or a->operator[](i)
const auto *Callee = dyn_cast<MemberExpr>(MCE->getCallee());
const auto *Callee = cast<MemberExpr>(MCE->getCallee());
if (FixMode == At) {
// Cases: a.operator[](i) => a.at(i) and a->operator[](i) => a->at(i)