summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Support/GCOV.h4
-rw-r--r--lib/IR/GCOV.cpp4
2 files changed, 6 insertions, 2 deletions
diff --git a/include/llvm/Support/GCOV.h b/include/llvm/Support/GCOV.h
index 469a9e3ef9..0aa716aac0 100644
--- a/include/llvm/Support/GCOV.h
+++ b/include/llvm/Support/GCOV.h
@@ -152,11 +152,11 @@ public:
}
bool readInt(uint32_t &Val) {
- StringRef Str = Buffer->getBuffer().slice(Cursor, Cursor+4);
- if (Str.empty()) {
+ if (Buffer->getBuffer().size() < Cursor+4) {
errs() << "Unexpected end of memory buffer: " << Cursor+4 << ".\n";
return false;
}
+ StringRef Str = Buffer->getBuffer().slice(Cursor, Cursor+4);
Cursor += 4;
Val = *(const uint32_t *)(Str.data());
return true;
diff --git a/lib/IR/GCOV.cpp b/lib/IR/GCOV.cpp
index 65ed3a5a84..a91e88c4e0 100644
--- a/lib/IR/GCOV.cpp
+++ b/lib/IR/GCOV.cpp
@@ -135,6 +135,10 @@ bool GCOVFunction::read(GCOVBuffer &Buff, GCOV::GCOVFormat Format) {
// This for loop adds the counts for each block. A second nested loop is
// required to combine the edge counts that are contained in the GCDA file.
for (uint32_t Line = 0; Count > 0; ++Line) {
+ if (Line >= Blocks.size()) {
+ errs() << "Unexpected number of edges.\n";
+ return false;
+ }
GCOVBlock &Block = *Blocks[Line];
for (size_t Edge = 0, End = Block.getNumEdges(); Edge < End; ++Edge) {
if (Count == 0) {