From c07e34ceedaab7e4cdfab5a62820f24168392004 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. llvm-svn: 147854 --- .../clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h | 2 ++ clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/clang/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h b/clang/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h index 23a1635788e3..fba5692d05e8 100644 --- a/clang/include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h +++ b/clang/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/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp b/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp index 50ebe3b7466e..e398bae60fc4 100644 --- a/clang/lib/StaticAnalyzer/Core/PathDiagnostic.cpp +++ b/clang/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)); }