From: Ted Kremenek Date: Mon, 12 Apr 2010 19:54:17 +0000 (+0000) Subject: Fix null dereference in 'WriteSourceLocation' when the FileEntry is null. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ec55c941f2846db48bce4ed6dd2ce339e1a48962;p=clang 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 --- 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 #include #include @@ -1036,8 +1036,15 @@ static void WriteSourceLocation(llvm::raw_ostream &OS, Location = SM->getInstantiationLoc(Location); std::pair 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)); }