[cfe-commits] r101060 - /cfe/trunk/lib/Basic/Diagnostic.cpp

Douglas Gregor dgregor at apple.com
Mon Apr 12 13:14:48 PDT 2010


On Apr 12, 2010, at 12:54 PM, Ted Kremenek wrote:

> Author: kremenek
> Date: Mon Apr 12 14:54:17 2010
> New Revision: 101060
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=101060&view=rev
> Log:
> Fix null dereference in 'WriteSourceLocation' when the FileEntry is null.

Looks great, thanks!

> Modified:
>    cfe/trunk/lib/Basic/Diagnostic.cpp
> 
> Modified: cfe/trunk/lib/Basic/Diagnostic.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Diagnostic.cpp?rev=101060&r1=101059&r2=101060&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Basic/Diagnostic.cpp (original)
> +++ cfe/trunk/lib/Basic/Diagnostic.cpp Mon Apr 12 14:54:17 2010
> @@ -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 @@
> 
>   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));
> }
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits





More information about the cfe-commits mailing list