]> granicus.if.org Git - clang/commitdiff
Make PathDiagnosticLocation more resilient to null Stmt pointers.
authorTed Kremenek <kremenek@apple.com>
Tue, 10 Jan 2012 15:26:13 +0000 (15:26 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 10 Jan 2012 15:26:13 +0000 (15:26 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@147854 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h
lib/StaticAnalyzer/Core/PathDiagnostic.cpp

index 23a1635788e3088256ec618bf62cb4a5adf74b82..fba5692d05e867d6873c092e3707c5c96282a8aa 100644 (file)
@@ -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());
   }
index 50ebe3b7466e09318b3ce8d6b5e67695a21069be..e398bae60fc46ec301a461f167b03c65f80d52de 100644 (file)
@@ -237,9 +237,15 @@ FullSourceLoc
     case RangeK:
       break;
     case StmtK:
+      // Defensive checking.
+      if (!S)
+        break;
       return FullSourceLoc(getValidSourceLocation(S, LAC),
                            const_cast<SourceManager&>(*SM));
     case DeclK:
+      // Defensive checking.
+      if (!D)
+        break;
       return FullSourceLoc(D->getLocation(), const_cast<SourceManager&>(*SM));
   }