Skip to content

Commit 6defc8e

Browse files
committed
Initialize member variable; NFC
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 5c8ba28 commit 6defc8e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace {
3030

3131
class ForwardDeclChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> {
3232
BugType Bug;
33-
mutable BugReporter *BR;
33+
mutable BugReporter *BR = nullptr;
3434
mutable RetainTypeChecker RTC;
3535
mutable llvm::DenseSet<const Type *> SystemTypes;
3636

@@ -107,6 +107,7 @@ class ForwardDeclChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> {
107107
void visitTypedef(const TypedefDecl *TD) const {
108108
RTC.visitTypedef(TD);
109109
auto QT = TD->getUnderlyingType().getCanonicalType();
110+
assert(BR && "expected nonnull BugReporter");
110111
if (BR->getSourceManager().isInSystemHeader(TD->getBeginLoc())) {
111112
if (auto *Type = QT.getTypePtrOrNull())
112113
SystemTypes.insert(Type);
@@ -146,6 +147,7 @@ class ForwardDeclChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> {
146147
if (Kind != TagTypeKind::Struct && Kind != TagTypeKind::Class)
147148
return;
148149

150+
assert(BR && "expected nonnull BugReporter");
149151
if (BR->getSourceManager().isInSystemHeader(RDLocation))
150152
return;
151153

@@ -177,6 +179,7 @@ class ForwardDeclChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> {
177179
}
178180

179181
void visitVarDecl(const VarDecl *V, const Decl *DeclWithIssue) const {
182+
assert(BR && "expected nonnull BugReporter");
180183
if (BR->getSourceManager().isInSystemHeader(V->getBeginLoc()))
181184
return;
182185

@@ -194,6 +197,7 @@ class ForwardDeclChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> {
194197
}
195198

196199
void visitCallExpr(const CallExpr *CE, const Decl *DeclWithIssue) const {
200+
assert(BR && "expected nonnull BugReporter");
197201
if (BR->getSourceManager().isInSystemHeader(CE->getExprLoc()))
198202
return;
199203

@@ -211,6 +215,7 @@ class ForwardDeclChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> {
211215

212216
void visitConstructExpr(const CXXConstructExpr *CE,
213217
const Decl *DeclWithIssue) const {
218+
assert(BR && "expected nonnull BugReporter");
214219
if (BR->getSourceManager().isInSystemHeader(CE->getExprLoc()))
215220
return;
216221

@@ -228,6 +233,7 @@ class ForwardDeclChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> {
228233

229234
void visitObjCMessageExpr(const ObjCMessageExpr *E,
230235
const Decl *DeclWithIssue) const {
236+
assert(BR && "expected nonnull BugReporter");
231237
if (BR->getSourceManager().isInSystemHeader(E->getExprLoc()))
232238
return;
233239

@@ -309,6 +315,7 @@ class ForwardDeclChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> {
309315
const std::string TypeName = Type.getAsString();
310316
Os << Description << " uses a forward declared type '" << TypeName << "'";
311317

318+
assert(BR && "expected nonnull BugReporter");
312319
PathDiagnosticLocation BSLoc(SrcLoc, BR->getSourceManager());
313320
auto Report = std::make_unique<BasicBugReport>(Bug, Os.str(), BSLoc);
314321
Report->addRange(SrcRange);

0 commit comments

Comments
 (0)