From f660f4b1bedd6b614acf52108894b805b807c50d Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Tue, 10 Jan 2012 15:26:13 +0000 Subject: [PATCH] Make PathDiagnosticLocation more resilient to null Stmt pointers. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147854 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h | 2 ++ lib/StaticAnalyzer/Core/PathDiagnostic.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h b/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h index 23a1635788..fba5692d05 100644 --- a/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h +++ b/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h @@ -129,6 +129,7 @@ public: : K(StmtK), S(s), D(0), SM(&sm), Loc(genLocation(SourceLocation(), lac)), Range(genRange(lac)) { + assert(S); assert(Loc.isValid()); assert(Range.isValid()); } @@ -137,6 +138,7 @@ public: PathDiagnosticLocation(const Decl *d, const SourceManager &sm) : K(DeclK), S(0), D(d), SM(&sm), Loc(genLocation()), Range(genRange()) { + assert(D); assert(Loc.isValid()); assert(Range.isValid()); } diff --git a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp index 50ebe3b746..e398bae60f 100644 --- a/lib/StaticAnalyzer/Core/PathDiagnostic.cpp +++ b/lib/StaticAnalyzer/Core/PathDiagnostic.cpp @@ -237,9 +237,15 @@ FullSourceLoc case RangeK: break; case StmtK: + // Defensive checking. + if (!S) + break; return FullSourceLoc(getValidSourceLocation(S, LAC), const_cast(*SM)); case DeclK: + // Defensive checking. + if (!D) + break; return FullSourceLoc(D->getLocation(), const_cast(*SM)); } -- 2.40.0