Author: Aaron Ballman Date: 2025-04-10T08:10:16-04:00 New Revision: 71f629fc2a93e41577c09bdd782b2ba524ed5fea
URL: https://github.com/llvm/llvm-project/commit/71f629fc2a93e41577c09bdd782b2ba524ed5fea DIFF: https://github.com/llvm/llvm-project/commit/71f629fc2a93e41577c09bdd782b2ba524ed5fea.diff LOG: 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. Added: Modified: clang/lib/StaticAnalyzer/Checkers/WebKit/RetainPtrCtorAdoptChecker.cpp Removed: ################################################################################ diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RetainPtrCtorAdoptChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RetainPtrCtorAdoptChecker.cpp index 1f9a4712cedf6..fc3f510d1d499 100644 --- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RetainPtrCtorAdoptChecker.cpp +++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RetainPtrCtorAdoptChecker.cpp @@ -31,7 +31,7 @@ class RetainPtrCtorAdoptChecker : public Checker<check::ASTDecl<TranslationUnitDecl>> { private: BugType Bug; - mutable BugReporter *BR; + mutable BugReporter *BR = nullptr; mutable std::unique_ptr<RetainSummaryManager> Summaries; mutable llvm::DenseSet<const ValueDecl *> CreateOrCopyOutArguments; mutable RetainTypeChecker RTC; @@ -111,6 +111,7 @@ class RetainPtrCtorAdoptChecker } void visitCallExpr(const CallExpr *CE, const Decl *DeclWithIssue) const { + assert(BR && "expected nonnull BugReporter"); if (BR->getSourceManager().isInSystemHeader(CE->getExprLoc())) return; @@ -169,6 +170,7 @@ class RetainPtrCtorAdoptChecker void visitConstructExpr(const CXXConstructExpr *CE, const Decl *DeclWithIssue) const { + assert(BR && "expected nonnull BugReporter"); if (BR->getSourceManager().isInSystemHeader(CE->getExprLoc())) return; @@ -356,6 +358,7 @@ class RetainPtrCtorAdoptChecker Os << " " << condition; Os << "."; + assert(BR && "expected nonnull BugReporter"); PathDiagnosticLocation BSLoc(CE->getSourceRange().getBegin(), BR->getSourceManager()); auto Report = std::make_unique<BasicBugReport>(Bug, Os.str(), BSLoc); @@ -376,6 +379,7 @@ class RetainPtrCtorAdoptChecker Os << " " << condition; Os << "."; + assert(BR && "expected nonnull BugReporter"); PathDiagnosticLocation BSLoc(CE->getSourceRange().getBegin(), BR->getSourceManager()); auto Report = std::make_unique<BasicBugReport>(Bug, Os.str(), BSLoc); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits