]> granicus.if.org Git - clang/commitdiff
Do some safety checks.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 17 May 2011 22:09:53 +0000 (22:09 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 17 May 2011 22:09:53 +0000 (22:09 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131491 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Basic/SourceManager.cpp
tools/libclang/CIndex.cpp

index c3e03933e5e585ede2c79b975d76be24ed3588d4..ae7de2d3c95fbf8fc05cbee29961be0a5821f2b4 100644 (file)
@@ -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;
index f1a37d6906b04e56ddd371a19636cdf9969d65cf..00141184c70a1fd0a1835b2d11b03b8c6a6255aa 100644 (file)
@@ -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)