aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/DataExtractor.cpp
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2020-02-27 16:22:12 +0100
committerPavel Labath <pavel@labath.sk>2020-02-28 09:02:33 +0100
commit5754a61e57efaa9bec8ad8ea8589a73b27edb0a8 (patch)
tree7bd6e8d5d7af09a48a2a0c84653905c70342f008 /llvm/lib/Support/DataExtractor.cpp
parentc3595d1069277b4ab0df49d7139b6f1bbc94f21c (diff)
downloadllvm-5754a61e57efaa9bec8ad8ea8589a73b27edb0a8.zip
llvm-5754a61e57efaa9bec8ad8ea8589a73b27edb0a8.tar.gz
llvm-5754a61e57efaa9bec8ad8ea8589a73b27edb0a8.tar.bz2
[DataExtractor] Improve error message when we run off the end of the buffer
Summary: Include the offset at which this happened. Reviewers: dblaikie, jhenderson Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D75265
Diffstat (limited to 'llvm/lib/Support/DataExtractor.cpp')
-rw-r--r--llvm/lib/Support/DataExtractor.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/llvm/lib/Support/DataExtractor.cpp b/llvm/lib/Support/DataExtractor.cpp
index 3d19b4d..d6fd9a5 100644
--- a/llvm/lib/Support/DataExtractor.cpp
+++ b/llvm/lib/Support/DataExtractor.cpp
@@ -15,10 +15,11 @@
using namespace llvm;
-static void unexpectedEndReached(Error *E) {
+static void unexpectedEndReached(Error *E, uint64_t Offset) {
if (E)
*E = createStringError(errc::illegal_byte_sequence,
- "unexpected end of data");
+ "unexpected end of data at offset 0x%" PRIx64,
+ Offset);
}
static bool isError(Error *E) { return E && *E; }
@@ -33,7 +34,7 @@ static T getU(uint64_t *offset_ptr, const DataExtractor *de,
uint64_t offset = *offset_ptr;
if (!de->isValidOffsetForDataOfSize(offset, sizeof(T))) {
- unexpectedEndReached(Err);
+ unexpectedEndReached(Err, offset);
return val;
}
std::memcpy(&val, &Data[offset], sizeof(val));
@@ -56,7 +57,7 @@ static T *getUs(uint64_t *offset_ptr, T *dst, uint32_t count,
uint64_t offset = *offset_ptr;
if (!de->isValidOffsetForDataOfSize(offset, sizeof(*dst) * count)) {
- unexpectedEndReached(Err);
+ unexpectedEndReached(Err, offset);
return nullptr;
}
for (T *value_ptr = dst, *end = dst + count; value_ptr != end;
@@ -229,5 +230,5 @@ void DataExtractor::skip(Cursor &C, uint64_t Length) const {
if (isValidOffsetForDataOfSize(C.Offset, Length))
C.Offset += Length;
else
- unexpectedEndReached(&C.Err);
+ unexpectedEndReached(&C.Err, C.Offset);
}