From: Argyrios Kyrtzidis Date: Fri, 4 Nov 2011 23:43:06 +0000 (+0000) Subject: Check for invalid after calling getSLocEntry, for safety. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a246d270156a55999ecfa4099a0967ec4c9a254e;p=clang Check for invalid after calling getSLocEntry, for safety. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143748 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 62b6615f1f..5555557b98 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -881,7 +881,11 @@ public: /// offset from the start of the buffer of the location. std::pair 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 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 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())