diff options
| author | Ted Kremenek <kremenek@apple.com> | 2009-01-26 21:50:21 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2009-01-26 21:50:21 +0000 |
| commit | 978b5beceadc7e001b1084acc31731203ab610ff (patch) | |
| tree | b707731fbc09235bac5eba74cb32a11daf64d385 | |
| parent | eb8c8fbd63922f9665a6838b4c2f8eebf4752b08 (diff) | |
| download | bcm5719-llvm-978b5beceadc7e001b1084acc31731203ab610ff.tar.gz bcm5719-llvm-978b5beceadc7e001b1084acc31731203ab610ff.zip | |
Add version number checking to PTH files.
llvm-svn: 63047
| -rw-r--r-- | clang/Driver/CacheTokens.cpp | 1 | ||||
| -rw-r--r-- | clang/lib/Lex/PTHLexer.cpp | 10 |
2 files changed, 9 insertions, 2 deletions
diff --git a/clang/Driver/CacheTokens.cpp b/clang/Driver/CacheTokens.cpp index 975d3648ee2..aef59cbe352 100644 --- a/clang/Driver/CacheTokens.cpp +++ b/clang/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/clang/lib/Lex/PTHLexer.cpp b/clang/lib/Lex/PTHLexer.cpp index 747ec101566..54269c9ee15 100644 --- a/clang/lib/Lex/PTHLexer.cpp +++ b/clang/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) |

