From 5037674ae2d41705461b64b8d894f97ebd437ee4 Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Thu, 21 Apr 2016 22:37:55 +0000 Subject: Fix PDB warnings and test llvm-svn: 267071 --- llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp | 20 +++++++------------- llvm/lib/DebugInfo/PDB/Raw/PDBStream.cpp | 11 ++--------- 2 files changed, 9 insertions(+), 22 deletions(-) (limited to 'llvm/lib/DebugInfo') diff --git a/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp b/llvm/lib/DebugInfo/PDB/Raw/PDBFile.cpp index fc5231f552b..12a717db49b 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> 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 -std::error_code checkOffset(MemoryBufferRef M, ArrayRef AR) { +static std::error_code checkOffset(MemoryBufferRef M, ArrayRef 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 MemBuffer) { Context.reset(new PDBContext()); Context->Buffer = std::move(MemBuffer); @@ -130,6 +120,10 @@ std::error_code PDBFile::parseFileHeaders() { Context->SB = reinterpret_cast(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); diff --git a/llvm/lib/DebugInfo/PDB/Raw/PDBStream.cpp b/llvm/lib/DebugInfo/PDB/Raw/PDBStream.cpp index 310454df824..c20ffc914d2 100644 --- a/llvm/lib/DebugInfo/PDB/Raw/PDBStream.cpp +++ b/llvm/lib/DebugInfo/PDB/Raw/PDBStream.cpp @@ -12,14 +12,6 @@ using namespace llvm; -static uint64_t bytesToBlocks(uint64_t NumBytes, uint64_t BlockSize) { - return alignTo(NumBytes, BlockSize) / BlockSize; -} - -static uint64_t blockToOffset(uint64_t BlockNumber, uint64_t BlockSize) { - return BlockNumber * BlockSize; -} - PDBStream::PDBStream(uint32_t StreamIdx, const PDBFile &File) : Pdb(File) { this->StreamLength = Pdb.getStreamByteSize(StreamIdx); this->BlockList = Pdb.getStreamBlockList(StreamIdx); @@ -73,7 +65,8 @@ std::error_code PDBStream::readBytes(void *Dest, uint32_t Length) { while (BytesLeft > 0) { uint32_t StreamBlockAddr = this->BlockList[BlockNum]; uint64_t StreamBlockOffset = - blockToOffset(StreamBlockAddr, Pdb.getBlockSize()) + OffsetInBlock; + PDBFile::blockToOffset(StreamBlockAddr, Pdb.getBlockSize()) + + OffsetInBlock; StringRef Data = Pdb.getBlockData(StreamBlockAddr, Pdb.getBlockSize()); -- cgit v1.2.3