[preprocessing record] Add some sanity checks for the preprocessed entity index

to make sure we don't crash on release if the index is not valid.

rdar://13089714

llvm-svn: 175010
This commit is contained in:
Argyrios Kyrtzidis 2013-02-12 21:41:23 +00:00
parent 3ea602cd30
commit 962b2210cc
1 changed files with 8 additions and 4 deletions

View File

@ -92,8 +92,10 @@ bool PreprocessingRecord::isEntityInFileID(iterator PPEI, FileID FID) {
int Pos = PPEI.Position;
if (Pos < 0) {
assert(unsigned(-Pos-1) < LoadedPreprocessedEntities.size() &&
"Out-of bounds loaded preprocessed entity");
if (unsigned(-Pos-1) >= LoadedPreprocessedEntities.size()) {
assert(0 && "Out-of bounds loaded preprocessed entity");
return false;
}
assert(ExternalSource && "No external source to load from");
unsigned LoadedIndex = LoadedPreprocessedEntities.size()+Pos;
if (PreprocessedEntity *PPE = LoadedPreprocessedEntities[LoadedIndex])
@ -113,8 +115,10 @@ bool PreprocessingRecord::isEntityInFileID(iterator PPEI, FileID FID) {
FID, SourceMgr);
}
assert(unsigned(Pos) < PreprocessedEntities.size() &&
"Out-of bounds local preprocessed entity");
if (unsigned(Pos) >= PreprocessedEntities.size()) {
assert(0 && "Out-of bounds local preprocessed entity");
return false;
}
return isPreprocessedEntityIfInFileID(PreprocessedEntities[Pos],
FID, SourceMgr);
}