diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-04-12 19:54:17 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-04-12 19:54:17 +0000 |
commit | ec55c941f2846db48bce4ed6dd2ce339e1a48962 (patch) | |
tree | e70b1dcc1eeeb4fd57246ff5a2a1d169065eafae /lib/Basic/Diagnostic.cpp | |
parent | b846debc1b22a37228efe4aa87b34482d15b6a3c (diff) |
Fix null dereference in 'WriteSourceLocation' when the FileEntry is null.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101060 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Basic/Diagnostic.cpp')
-rw-r--r-- | lib/Basic/Diagnostic.cpp | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/lib/Basic/Diagnostic.cpp b/lib/Basic/Diagnostic.cpp index 738c27ccae..1eeb25b877 100644 --- a/lib/Basic/Diagnostic.cpp +++ b/lib/Basic/Diagnostic.cpp @@ -11,24 +11,24 @@ // //===----------------------------------------------------------------------===// -#include "clang/Basic/Diagnostic.h" -#include "clang/Basic/PartialDiagnostic.h" - -#include "clang/Lex/LexDiagnostic.h" -#include "clang/Parse/ParseDiagnostic.h" #include "clang/AST/ASTDiagnostic.h" -#include "clang/Sema/SemaDiagnostic.h" -#include "clang/Frontend/FrontendDiagnostic.h" #include "clang/Analysis/AnalysisDiagnostic.h" -#include "clang/Driver/DriverDiagnostic.h" - +#include "clang/Basic/Diagnostic.h" #include "clang/Basic/FileManager.h" #include "clang/Basic/IdentifierTable.h" +#include "clang/Basic/PartialDiagnostic.h" #include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceManager.h" +#include "clang/Driver/DriverDiagnostic.h" +#include "clang/Frontend/FrontendDiagnostic.h" +#include "clang/Lex/LexDiagnostic.h" +#include "clang/Parse/ParseDiagnostic.h" +#include "clang/Sema/SemaDiagnostic.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" + #include <vector> #include <map> #include <cstring> @@ -1036,8 +1036,15 @@ static void WriteSourceLocation(llvm::raw_ostream &OS, Location = SM->getInstantiationLoc(Location); std::pair<FileID, unsigned> Decomposed = SM->getDecomposedLoc(Location); - - WriteString(OS, SM->getFileEntryForID(Decomposed.first)->getName()); + + const FileEntry *FE = SM->getFileEntryForID(Decomposed.first); + if (FE) + WriteString(OS, FE->getName()); + else { + // Fallback to using the buffer name when there is no entry. + WriteString(OS, SM->getBuffer(Decomposed.first)->getBufferIdentifier()); + } + WriteUnsigned(OS, SM->getLineNumber(Decomposed.first, Decomposed.second)); WriteUnsigned(OS, SM->getColumnNumber(Decomposed.first, Decomposed.second)); } |