[libclang] Add some checks to make sure the given CXTranslationUnit is not null, before using it.

llvm-svn: 178800
This commit is contained in:
Argyrios Kyrtzidis 2013-04-04 22:40:59 +00:00
parent 3903247e48
commit 0e95fcacdf
1 changed files with 7 additions and 1 deletions

View File

@ -2927,6 +2927,9 @@ CXString clang_getTranslationUnitSpelling(CXTranslationUnit CTUnit) {
}
CXCursor clang_getTranslationUnitCursor(CXTranslationUnit TU) {
if (!TU)
return clang_getNullCursor();
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
return MakeCXCursor(CXXUnit->getASTContext().getTranslationUnitDecl(), TU);
}
@ -4914,6 +4917,9 @@ void clang_tokenize(CXTranslationUnit TU, CXSourceRange Range,
if (NumTokens)
*NumTokens = 0;
if (!TU)
return;
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
if (!CXXUnit || !Tokens || !NumTokens)
return;
@ -5610,7 +5616,7 @@ extern "C" {
void clang_annotateTokens(CXTranslationUnit TU,
CXToken *Tokens, unsigned NumTokens,
CXCursor *Cursors) {
if (NumTokens == 0 || !Tokens || !Cursors) {
if (!TU || NumTokens == 0 || !Tokens || !Cursors) {
LOG_FUNC_SECTION { *Log << "<null input>"; }
return;
}