aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-05-17 22:09:53 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2011-05-17 22:09:53 +0000
commit5adc0515aaacb6c4d4f0c9626d86c1e5c177467c (patch)
tree02e0756b439d9ca0e133f19fae127fa6c9de1889
parentbadea57d1db45caa95e71a256f4f4cf94fe20451 (diff)
Do some safety checks.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131491 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Basic/SourceManager.cpp6
-rw-r--r--tools/libclang/CIndex.cpp16
2 files changed, 11 insertions, 11 deletions
diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp
index c3e03933e5..ae7de2d3c9 100644
--- a/lib/Basic/SourceManager.cpp
+++ b/lib/Basic/SourceManager.cpp
@@ -961,6 +961,12 @@ static void ComputeLineNumbers(Diagnostic &Diag, ContentCache *FI,
/// about to emit a diagnostic.
unsigned SourceManager::getLineNumber(FileID FID, unsigned FilePos,
bool *Invalid) const {
+ if (FID.isInvalid()) {
+ if (Invalid)
+ *Invalid = true;
+ return 1;
+ }
+
ContentCache *Content;
if (LastLineNoFileIDQuery == FID)
Content = LastLineNoContentCache;
diff --git a/tools/libclang/CIndex.cpp b/tools/libclang/CIndex.cpp
index f1a37d6906..00141184c7 100644
--- a/tools/libclang/CIndex.cpp
+++ b/tools/libclang/CIndex.cpp
@@ -2819,17 +2819,8 @@ void clang_getSpellingLocation(CXSourceLocation location,
unsigned *offset) {
SourceLocation Loc = SourceLocation::getFromRawEncoding(location.int_data);
- if (!location.ptr_data[0] || Loc.isInvalid()) {
- if (file)
- *file = 0;
- if (line)
- *line = 0;
- if (column)
- *column = 0;
- if (offset)
- *offset = 0;
- return;
- }
+ if (!location.ptr_data[0] || Loc.isInvalid())
+ return createNullLocation(file, line, column, offset);
const SourceManager &SM =
*static_cast<const SourceManager*>(location.ptr_data[0]);
@@ -2847,6 +2838,9 @@ void clang_getSpellingLocation(CXSourceLocation location,
FileID FID = LocInfo.first;
unsigned FileOffset = LocInfo.second;
+ if (FID.isInvalid())
+ return createNullLocation(file, line, column, offset);
+
if (file)
*file = (void *)SM.getFileEntryForID(FID);
if (line)