Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit c141b51

Browse files
committed
Switch PTH format from a 7 byte magic number to an 8 byte one, to avoid
misaligned reads throughout the file. Bump PTH format version to 10. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@162076 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent e276cfc commit c141b51

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

include/clang/Lex/PTHManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class PTHManager : public IdentifierInfoLookup {
101101

102102
public:
103103
// The current PTH version.
104-
enum { Version = 9 };
104+
enum { Version = 10 };
105105

106106
~PTHManager();
107107

lib/Frontend/CacheTokens.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ Offset PTHWriter::EmitCachedSpellings() {
447447

448448
void PTHWriter::GeneratePTH(const std::string &MainFile) {
449449
// Generate the prologue.
450-
Out << "cfe-pth";
450+
Out << "cfe-pth" << '\0';
451451
Emit32(PTHManager::Version);
452452

453453
// Leave 4 words for the prologue.

lib/Lex/PTHLexer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,14 +452,14 @@ PTHManager *PTHManager::Create(const std::string &file,
452452
const unsigned char *BufEnd = (unsigned char*)File->getBufferEnd();
453453

454454
// Check the prologue of the file.
455-
if ((BufEnd - BufBeg) < (signed)(sizeof("cfe-pth") + 3 + 4) ||
456-
memcmp(BufBeg, "cfe-pth", sizeof("cfe-pth") - 1) != 0) {
455+
if ((BufEnd - BufBeg) < (signed)(sizeof("cfe-pth") + 4 + 4) ||
456+
memcmp(BufBeg, "cfe-pth", sizeof("cfe-pth")) != 0) {
457457
Diags.Report(diag::err_invalid_pth_file) << file;
458458
return 0;
459459
}
460460

461461
// Read the PTH version.
462-
const unsigned char *p = BufBeg + (sizeof("cfe-pth") - 1);
462+
const unsigned char *p = BufBeg + (sizeof("cfe-pth"));
463463
unsigned Version = ReadLE32(p);
464464

465465
if (Version < PTHManager::Version) {

0 commit comments

Comments
 (0)