aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Kremenek <kremenek@apple.com>2009-01-26 21:50:21 +0000
committerTed Kremenek <kremenek@apple.com>2009-01-26 21:50:21 +0000
commit67d15050bbea16ae256e204ecd464f2e454c3c99 (patch)
tree91804f83fe24b1c3e6e478af18474e4491e8d178
parente1b6498c41b94c3bc5cede17b0702282543385ef (diff)
Add version number checking to PTH files.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63047 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--Driver/CacheTokens.cpp1
-rw-r--r--lib/Lex/PTHLexer.cpp10
2 files changed, 9 insertions, 2 deletions
diff --git a/Driver/CacheTokens.cpp b/Driver/CacheTokens.cpp
index 975d3648ee..aef59cbe35 100644
--- a/Driver/CacheTokens.cpp
+++ b/Driver/CacheTokens.cpp
@@ -456,6 +456,7 @@ void PTHWriter::EmitCachedSpellings() {
void PTHWriter::GeneratePTH() {
// Generate the prologue.
Out << "cfe-pth";
+ Emit32(PTHManager::Version);
Offset JumpOffset = Out.tell();
Emit32(0);
diff --git a/lib/Lex/PTHLexer.cpp b/lib/Lex/PTHLexer.cpp
index 747ec10156..54269c9ee1 100644
--- a/lib/Lex/PTHLexer.cpp
+++ b/lib/Lex/PTHLexer.cpp
@@ -522,12 +522,18 @@ PTHManager* PTHManager::Create(const std::string& file) {
const unsigned char* BufEnd = (unsigned char*)File->getBufferEnd();
// Check the prologue of the file.
- if ((BufEnd - BufBeg) < (unsigned) (sizeof("cfe-pth") + 3) ||
+ if ((BufEnd - BufBeg) < (unsigned) (sizeof("cfe-pth") + 3 + 4) ||
memcmp(BufBeg, "cfe-pth", sizeof("cfe-pth") - 1) != 0)
return 0;
- // Compute the address of the index table at the end of the PTH file.
+ // Read the PTH version.
const unsigned char *p = BufBeg + (sizeof("cfe-pth") - 1);
+ unsigned Version = ReadLE32(p);
+
+ if (Version != PTHManager::Version)
+ return 0;
+
+ // Compute the address of the index table at the end of the PTH file.
const unsigned char *EndTable = BufBeg + ReadLE32(p);
if (EndTable >= BufEnd)