summaryrefslogtreecommitdiff
path: root/lib/ProfileData
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-03-21 20:42:28 +0000
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2014-03-21 20:42:28 +0000
commitebaeaa934e6c581689edf6acd43d1c6e56d9ab08 (patch)
tree950a4aee14d4e047cdd3d9a753fe0cd19144e6b4 /lib/ProfileData
parent56db3a97cdc241baf425fa6ebc64383a4902517e (diff)
downloadllvm-ebaeaa934e6c581689edf6acd43d1c6e56d9ab08.tar.gz
llvm-ebaeaa934e6c581689edf6acd43d1c6e56d9ab08.tar.bz2
llvm-ebaeaa934e6c581689edf6acd43d1c6e56d9ab08.tar.xz
InstrProf: Actually detect bad headers
<rdar://problem/15950346> git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204510 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ProfileData')
-rw-r--r--lib/ProfileData/InstrProf.cpp2
-rw-r--r--lib/ProfileData/InstrProfReader.cpp12
2 files changed, 7 insertions, 7 deletions
diff --git a/lib/ProfileData/InstrProf.cpp b/lib/ProfileData/InstrProf.cpp
index ecabdd75bd..850f61354e 100644
--- a/lib/ProfileData/InstrProf.cpp
+++ b/lib/ProfileData/InstrProf.cpp
@@ -29,6 +29,8 @@ class InstrProfErrorCategoryType : public error_category {
return "End of File";
case instrprof_error::bad_magic:
return "Invalid file format (bad magic)";
+ case instrprof_error::bad_header:
+ return "Invalid header";
case instrprof_error::unsupported_version:
return "Unsupported format version";
case instrprof_error::too_large:
diff --git a/lib/ProfileData/InstrProfReader.cpp b/lib/ProfileData/InstrProfReader.cpp
index c563355599..d2e5fbd9b9 100644
--- a/lib/ProfileData/InstrProfReader.cpp
+++ b/lib/ProfileData/InstrProfReader.cpp
@@ -43,8 +43,7 @@ error_code InstrProfReader::create(std::string Path,
if (Buffer->getBufferSize() < sizeof(uint64_t)) {
Result.reset(new TextInstrProfReader(Buffer));
- Result->readHeader();
- return instrprof_error::success;
+ return Result->readHeader();
}
uint64_t Magic = *(uint64_t *)Buffer->getBufferStart();
@@ -53,8 +52,7 @@ error_code InstrProfReader::create(std::string Path,
Result.reset(new RawInstrProfReader(Buffer));
else
Result.reset(new TextInstrProfReader(Buffer));
- Result->readHeader();
- return instrprof_error::success;
+ return Result->readHeader();
}
void InstrProfIterator::Increment() {
@@ -113,13 +111,13 @@ RawInstrProfReader::RawInstrProfReader(std::unique_ptr<MemoryBuffer> &DataBuffer
error_code RawInstrProfReader::readHeader() {
if (DataBuffer->getBufferSize() < sizeof(RawHeader))
- return error(instrprof_error::malformed);
+ return error(instrprof_error::bad_header);
const RawHeader *Header = (RawHeader *)DataBuffer->getBufferStart();
if (Header->Magic == getRawMagic())
ShouldSwapBytes = false;
else {
if (sys::SwapByteOrder(Header->Magic) != getRawMagic())
- return error(instrprof_error::malformed);
+ return error(instrprof_error::bad_magic);
ShouldSwapBytes = true;
}
@@ -142,7 +140,7 @@ error_code RawInstrProfReader::readHeader(const RawHeader &Header) {
size_t FileSize = NamesOffset + sizeof(char) * NamesSize;
if (FileSize != DataBuffer->getBufferSize())
- return error(instrprof_error::malformed);
+ return error(instrprof_error::bad_header);
Data = (ProfileData *)(DataBuffer->getBufferStart() + DataOffset);
DataEnd = Data + DataSize;