libclang: audit all APIs that accept a CXTranslationUnit to make sure that
checks for invalid translation unit are in place. Also, while there, add log
output for this case.
llvm-svn: 201155
diff --git a/clang/tools/libclang/CXSourceLocation.cpp b/clang/tools/libclang/CXSourceLocation.cpp
index 7371177..c17449a 100644
--- a/clang/tools/libclang/CXSourceLocation.cpp
+++ b/clang/tools/libclang/CXSourceLocation.cpp
@@ -122,7 +122,11 @@
CXFile file,
unsigned line,
unsigned column) {
- if (!TU || !file)
+ if (cxtu::isNotUseableTU(TU)) {
+ LOG_BAD_TU(TU);
+ return clang_getNullLocation();
+ }
+ if (!file)
return clang_getNullLocation();
if (line == 0 || column == 0)
return clang_getNullLocation();
@@ -151,9 +155,13 @@
CXSourceLocation clang_getLocationForOffset(CXTranslationUnit TU,
CXFile file,
unsigned offset) {
- if (!TU || !file)
+ if (cxtu::isNotUseableTU(TU)) {
+ LOG_BAD_TU(TU);
return clang_getNullLocation();
-
+ }
+ if (!file)
+ return clang_getNullLocation();
+
ASTUnit *CXXUnit = cxtu::getASTUnit(TU);
SourceLocation SLoc