]> granicus.if.org Git - clang/commitdiff
Check for invalid after calling getSLocEntry, for safety.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 4 Nov 2011 23:43:06 +0000 (23:43 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Fri, 4 Nov 2011 23:43:06 +0000 (23:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143748 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/SourceManager.h

index 62b6615f1f1bdc5ed43a81d8e6b7f1350fab75d5..5555557b98dcbc022f4afa354998fc2b486f10b1 100644 (file)
@@ -881,7 +881,11 @@ public:
   /// offset from the start of the buffer of the location.
   std::pair<FileID, unsigned> getDecomposedLoc(SourceLocation Loc) const {
     FileID FID = getFileID(Loc);
-    return std::make_pair(FID, Loc.getOffset()-getSLocEntry(FID).getOffset());
+    bool Invalid = false;
+    const SrcMgr::SLocEntry &E = getSLocEntry(FID, &Invalid);
+    if (Invalid)
+      return std::make_pair(FileID(), 0);
+    return std::make_pair(FID, Loc.getOffset()-E.getOffset());
   }
 
   /// getDecomposedExpansionLoc - Decompose the specified location into a raw
@@ -890,7 +894,10 @@ public:
   std::pair<FileID, unsigned>
   getDecomposedExpansionLoc(SourceLocation Loc) const {
     FileID FID = getFileID(Loc);
-    const SrcMgr::SLocEntry *E = &getSLocEntry(FID);
+    bool Invalid = false;
+    const SrcMgr::SLocEntry *E = &getSLocEntry(FID, &Invalid);
+    if (Invalid)
+      return std::make_pair(FileID(), 0);
 
     unsigned Offset = Loc.getOffset()-E->getOffset();
     if (Loc.isFileID())
@@ -905,7 +912,10 @@ public:
   std::pair<FileID, unsigned>
   getDecomposedSpellingLoc(SourceLocation Loc) const {
     FileID FID = getFileID(Loc);
-    const SrcMgr::SLocEntry *E = &getSLocEntry(FID);
+    bool Invalid = false;
+    const SrcMgr::SLocEntry *E = &getSLocEntry(FID, &Invalid);
+    if (Invalid)
+      return std::make_pair(FileID(), 0);
 
     unsigned Offset = Loc.getOffset()-E->getOffset();
     if (Loc.isFileID())