Skip to content

Commit c691020

Browse files
authored
[NFC] [clang-tidy] Fix potential SA issues. (llvm#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 llvm#101).
1 parent 6984f94 commit c691020

File tree

3 files changed

+3
-2
lines changed

3 files changed

+3
-2
lines changed

clang-tools-extra/clang-tidy/ExpandModularHeadersPPCallbacks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class ExpandModularHeadersPPCallbacks : public PPCallbacks {
137137
std::unique_ptr<Preprocessor> PP;
138138
bool EnteredMainFile = false;
139139
bool StartedLexing = false;
140-
Token CurrentToken;
140+
Token CurrentToken = Token();
141141
};
142142

143143
} // namespace tooling

clang-tools-extra/clang-tidy/bugprone/FloatLoopCounterCheck.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ void FloatLoopCounterCheck::registerMatchers(MatchFinder *Finder) {
3131

3232
void FloatLoopCounterCheck::check(const MatchFinder::MatchResult &Result) {
3333
const auto *FS = Result.Nodes.getNodeAs<ForStmt>("for");
34+
assert(FS && "FS should not be null");
3435

3536
diag(FS->getInc()->getBeginLoc(), "loop induction expression should not have "
3637
"floating-point type")

clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsAvoidUncheckedContainerAccessCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void ProBoundsAvoidUncheckedContainerAccessCheck::check(
176176
}
177177
} else if (const auto *MCE = dyn_cast<CXXMemberCallExpr>(MatchedExpr)) {
178178
// Case: a.operator[](i) or a->operator[](i)
179-
const auto *Callee = dyn_cast<MemberExpr>(MCE->getCallee());
179+
const auto *Callee = cast<MemberExpr>(MCE->getCallee());
180180

181181
if (FixMode == At) {
182182
// Cases: a.operator[](i) => a.at(i) and a->operator[](i) => a->at(i)

0 commit comments

Comments
 (0)