diff options
author | Reid Kleckner <rnk@google.com> | 2016-04-21 22:37:55 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2016-04-21 22:37:55 +0000 |
commit | 5037674ae2d41705461b64b8d894f97ebd437ee4 (patch) | |
tree | 8bc6046d754c7ef23b1175cd81afc287c87d5816 /llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp | |
parent | 025191d42feb2636026efeb93d9f5b05de0571ea (diff) | |
download | llvm-5037674ae2d41705461b64b8d894f97ebd437ee4.zip llvm-5037674ae2d41705461b64b8d894f97ebd437ee4.tar.gz llvm-5037674ae2d41705461b64b8d894f97ebd437ee4.tar.bz2 |
Fix PDB warnings and test
llvm-svn: 267071
Diffstat (limited to 'llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp')
-rw-r--r-- | llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp b/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp index fc5231f..12a717d 100644 --- a/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp +++ b/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp @@ -50,9 +50,8 @@ struct llvm::PDBContext { DenseMap<uint32_t, std::vector<uint32_t>> StreamMap; }; -namespace { -std::error_code checkOffset(MemoryBufferRef M, uintptr_t Addr, - const uint64_t Size) { +static std::error_code checkOffset(MemoryBufferRef M, uintptr_t Addr, + const uint64_t Size) { if (Addr + Size < Addr || Addr + Size < Size || Addr + Size > uintptr_t(M.getBufferEnd()) || Addr < uintptr_t(M.getBufferStart())) { @@ -62,19 +61,10 @@ std::error_code checkOffset(MemoryBufferRef M, uintptr_t Addr, } template <typename T> -std::error_code checkOffset(MemoryBufferRef M, ArrayRef<T> AR) { +static std::error_code checkOffset(MemoryBufferRef M, ArrayRef<T> AR) { return checkOffset(M, uintptr_t(AR.data()), (uint64_t)AR.size() * sizeof(T)); } -uint64_t bytesToBlocks(uint64_t NumBytes, uint64_t BlockSize) { - return alignTo(NumBytes, BlockSize) / BlockSize; -} - -uint64_t blockToOffset(uint64_t BlockNumber, uint64_t BlockSize) { - return BlockNumber * BlockSize; -} -} - PDBFile::PDBFile(std::unique_ptr<MemoryBuffer> MemBuffer) { Context.reset(new PDBContext()); Context->Buffer = std::move(MemBuffer); @@ -130,6 +120,10 @@ std::error_code PDBFile::parseFileHeaders() { Context->SB = reinterpret_cast<const SuperBlock *>(BufferRef.getBufferStart()); const SuperBlock *SB = Context->SB; + // Check the magic bytes. + if (memcmp(SB->MagicBytes, Magic, sizeof(Magic)) != 0) + return std::make_error_code(std::errc::illegal_byte_sequence); + // We don't support blocksizes which aren't a multiple of four bytes. if (SB->BlockSize % sizeof(support::ulittle32_t) != 0) return std::make_error_code(std::errc::not_supported); |