[cfe-commits] r131491 - in /cfe/trunk: lib/Basic/SourceManager.cpp tools/libclang/CIndex.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue May 17 15:09:53 PDT 2011


Author: akirtzidis
Date: Tue May 17 17:09:53 2011
New Revision: 131491

URL: http://llvm.org/viewvc/llvm-project?rev=131491&view=rev
Log:
Do some safety checks.

Modified:
    cfe/trunk/lib/Basic/SourceManager.cpp
    cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=131491&r1=131490&r2=131491&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Tue May 17 17:09:53 2011
@@ -961,6 +961,12 @@
 /// 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;

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=131491&r1=131490&r2=131491&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Tue May 17 17:09:53 2011
@@ -2819,17 +2819,8 @@
                                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 @@
   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)





More information about the cfe-commits mailing list