aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/PTHLexer.cpp
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-01-21 07:34:28 +0000
committerTed Kremenek <kremenek@apple.com>2009-01-21 07:34:28 +0000
commitcdd8f2153e18796e9e2a126ebcbd4f3e1bd7135b (patch)
treeaa19733e5f0e0fbced7f20bbbaad94237b9a8794 /lib/Lex/PTHLexer.cpp
parent6353bebfc2d6d19e15f1b2c673507cdb6985270f (diff)
Don't crash on empty PTH files. This fixes <rdar://problem/6512714>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@62673 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Lex/PTHLexer.cpp')
-rw-r--r--lib/Lex/PTHLexer.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp
index 494cea50e6..81349171fe 100644
--- a/lib/Lex/PTHLexer.cpp
+++ b/lib/Lex/PTHLexer.cpp
@@ -484,6 +484,10 @@ private:
public:
PTHFileLookup() {};
+ bool isEmpty() const {
+ return FileMap.empty();
+ }
+
Val Lookup(const FileEntry* FE) {
const char* s = FE->getName();
unsigned size = strlen(s);
@@ -563,12 +567,16 @@ PTHManager* PTHManager::Create(const std::string& file) {
llvm::OwningPtr<PTHFileLookup> FL(new PTHFileLookup());
FL->ReadTable(FileTable);
+
+ if (FL->isEmpty())
+ return 0;
// Get the location of the table mapping from persistent ids to the
// data needed to reconstruct identifiers.
const unsigned char* IDTableOffset = EndTable + sizeof(uint32_t)*1;
const unsigned char* IData = BufBeg + Read32(IDTableOffset);
- if (!(IData > BufBeg && IData < BufEnd)) {
+
+ if (!(IData >= BufBeg && IData < BufEnd)) {
assert(false && "Invalid PTH file.");
return 0; // FIXME: Proper error diagnostic?
}
@@ -576,25 +584,27 @@ PTHManager* PTHManager::Create(const std::string& file) {
// Get the location of the lexigraphically-sorted table of persistent IDs.
const unsigned char* SortedIdTableOffset = EndTable + sizeof(uint32_t)*2;
const unsigned char* SortedIdTable = BufBeg + Read32(SortedIdTableOffset);
- if (!(SortedIdTable > BufBeg && SortedIdTable < BufEnd)) {
+ if (!(SortedIdTable >= BufBeg && SortedIdTable < BufEnd)) {
assert(false && "Invalid PTH file.");
return 0; // FIXME: Proper error diagnostic?
}
// Get the number of IdentifierInfos and pre-allocate the identifier cache.
uint32_t NumIds = Read32(IData);
-
+
// Pre-allocate the peristent ID -> IdentifierInfo* cache. We use calloc()
// so that we in the best case only zero out memory once when the OS returns
// us new pages.
- IdentifierInfo** PerIDCache =
- (IdentifierInfo**)calloc(NumIds, sizeof(*PerIDCache));
+ IdentifierInfo** PerIDCache = 0;
- if (!PerIDCache) {
- assert(false && "Could not allocate Persistent ID cache.");
- return 0;
+ if (NumIds) {
+ PerIDCache = (IdentifierInfo**)calloc(NumIds, sizeof(*PerIDCache));
+ if (!PerIDCache) {
+ assert(false && "Could not allocate Persistent ID cache.");
+ return 0;
+ }
}
-
+
// Create the new PTHManager.
return new PTHManager(File.take(), FL.take(), IData, PerIDCache,
SortedIdTable, NumIds);