[cfe-commits] r62673 - /cfe/trunk/lib/Lex/PTHLexer.cpp
Ted Kremenek
kremenek at apple.com
Tue Jan 20 23:34:28 PST 2009
Author: kremenek
Date: Wed Jan 21 01:34:28 2009
New Revision: 62673
URL: http://llvm.org/viewvc/llvm-project?rev=62673&view=rev
Log:
Don't crash on empty PTH files. This fixes <rdar://problem/6512714>.
Modified:
cfe/trunk/lib/Lex/PTHLexer.cpp
Modified: cfe/trunk/lib/Lex/PTHLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PTHLexer.cpp?rev=62673&r1=62672&r2=62673&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PTHLexer.cpp (original)
+++ cfe/trunk/lib/Lex/PTHLexer.cpp Wed Jan 21 01:34:28 2009
@@ -484,6 +484,10 @@
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 @@
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 @@
// 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);
More information about the cfe-commits
mailing list