Skip to content

Commit 71f629f

Browse files
authored
Initialize member variable; NFC (#135167)
This was found via a Coverity static analysis pass. There's no indication this was being used incorrectly in practice, but there are public interfaces which require `BR` to be non-null and valid, and `BR` was not being initialized by the constructor. This adds an in-class initializer for `BR` and some asserts, to be safe.
1 parent 6d98d45 commit 71f629f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

clang/lib/StaticAnalyzer/Checkers/WebKit/RetainPtrCtorAdoptChecker.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class RetainPtrCtorAdoptChecker
3131
: public Checker<check::ASTDecl<TranslationUnitDecl>> {
3232
private:
3333
BugType Bug;
34-
mutable BugReporter *BR;
34+
mutable BugReporter *BR = nullptr;
3535
mutable std::unique_ptr<RetainSummaryManager> Summaries;
3636
mutable llvm::DenseSet<const ValueDecl *> CreateOrCopyOutArguments;
3737
mutable RetainTypeChecker RTC;
@@ -111,6 +111,7 @@ class RetainPtrCtorAdoptChecker
111111
}
112112

113113
void visitCallExpr(const CallExpr *CE, const Decl *DeclWithIssue) const {
114+
assert(BR && "expected nonnull BugReporter");
114115
if (BR->getSourceManager().isInSystemHeader(CE->getExprLoc()))
115116
return;
116117

@@ -169,6 +170,7 @@ class RetainPtrCtorAdoptChecker
169170

170171
void visitConstructExpr(const CXXConstructExpr *CE,
171172
const Decl *DeclWithIssue) const {
173+
assert(BR && "expected nonnull BugReporter");
172174
if (BR->getSourceManager().isInSystemHeader(CE->getExprLoc()))
173175
return;
174176

@@ -356,6 +358,7 @@ class RetainPtrCtorAdoptChecker
356358
Os << " " << condition;
357359
Os << ".";
358360

361+
assert(BR && "expected nonnull BugReporter");
359362
PathDiagnosticLocation BSLoc(CE->getSourceRange().getBegin(),
360363
BR->getSourceManager());
361364
auto Report = std::make_unique<BasicBugReport>(Bug, Os.str(), BSLoc);
@@ -376,6 +379,7 @@ class RetainPtrCtorAdoptChecker
376379
Os << " " << condition;
377380
Os << ".";
378381

382+
assert(BR && "expected nonnull BugReporter");
379383
PathDiagnosticLocation BSLoc(CE->getSourceRange().getBegin(),
380384
BR->getSourceManager());
381385
auto Report = std::make_unique<BasicBugReport>(Bug, Os.str(), BSLoc);

0 commit comments

Comments
 (0)