From a6d3ab394c4cd854b5a7b600a578a7a75c69507c Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Fri, 5 Mar 2010 22:43:29 +0000 Subject: Check if 'Unit' is NULL before trying to iterate over the diagnostics. This obviates a null dereference that can occur when 'NumErrors' is not zero. llvm-svn: 97849 --- clang/tools/CIndex/CIndex.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'clang/tools/CIndex/CIndex.cpp') diff --git a/clang/tools/CIndex/CIndex.cpp b/clang/tools/CIndex/CIndex.cpp index f07b94fc51d..07bb7fbd83e 100644 --- a/clang/tools/CIndex/CIndex.cpp +++ b/clang/tools/CIndex/CIndex.cpp @@ -1003,7 +1003,8 @@ clang_createTranslationUnitFromSourceFile(CXIndex CIdx, // FIXME: Until we have broader testing, just drop the entire AST if we // encountered an error. if (NumErrors != Diags->getNumErrors()) { - if (CXXIdx->getDisplayDiagnostics()) { + // Make sure to check that 'Unit' is non-NULL. + if (CXXIdx->getDisplayDiagnostics() && Unit.get()) { for (ASTUnit::diag_iterator D = Unit->diag_begin(), DEnd = Unit->diag_end(); D != DEnd; ++D) { -- cgit v1.2.3