]> granicus.if.org Git - clang/commitdiff
Fix undefined behavior: don't bind a dereferenced null pointer to a reference.
authorRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 14 Aug 2012 04:19:29 +0000 (04:19 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Tue, 14 Aug 2012 04:19:29 +0000 (04:19 +0000)
No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161832 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/Diagnostic.h
lib/Basic/Diagnostic.cpp

index 8b4d3a0b608fca133b22af38f6284d4fd7005ae1..3997fb89ba8207ef7a58397e707c83b3070c3788 100644 (file)
@@ -267,16 +267,14 @@ private:
   }
 
   void PushDiagStatePoint(DiagState *State, SourceLocation L) {
-    FullSourceLoc Loc(L, *SourceMgr);
+    FullSourceLoc Loc(L, getSourceManager());
     // Make sure that DiagStatePoints is always sorted according to Loc.
-    assert((Loc.isValid() || DiagStatePoints.empty()) &&
-           "Adding invalid loc point after another point");
-    assert((Loc.isInvalid() || DiagStatePoints.empty() ||
-            DiagStatePoints.back().Loc.isInvalid() ||
+    assert(Loc.isValid() && "Adding invalid loc point");
+    assert(!DiagStatePoints.empty() &&
+           (DiagStatePoints.back().Loc.isInvalid() ||
             DiagStatePoints.back().Loc.isBeforeInTranslationUnitThan(Loc)) &&
            "Previous point loc comes after or is the same as new one");
-    DiagStatePoints.push_back(DiagStatePoint(State,
-                                             FullSourceLoc(Loc, *SourceMgr)));
+    DiagStatePoints.push_back(DiagStatePoint(State, Loc));
   }
 
   /// \brief Finds the DiagStatePoint that contains the diagnostic state of
index 60feb75c1ce28fa0801caf5ee7d05a0375e72f00..e68950200fd036db3db15a121f0ee6fbe53a6530 100644 (file)
@@ -119,7 +119,7 @@ void DiagnosticsEngine::Reset() {
   // Create a DiagState and DiagStatePoint representing diagnostic changes
   // through command-line.
   DiagStates.push_back(DiagState());
-  PushDiagStatePoint(&DiagStates.back(), SourceLocation());
+  DiagStatePoints.push_back(DiagStatePoint(&DiagStates.back(), FullSourceLoc()));
 }
 
 void DiagnosticsEngine::SetDelayedDiagnostic(unsigned DiagID, StringRef Arg1,