aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/DataExtractor.cpp
diff options
context:
space:
mode:
authorPavel Labath <pavel@labath.sk>2020-03-23 16:15:49 +0100
committerPavel Labath <pavel@labath.sk>2020-04-06 14:14:11 +0200
commita16fffa3f6add51fe1c6ee975ace56aa06a3bea7 (patch)
treef6437870891a7066feb1231d4b933ff4649df35e /llvm/lib/Support/DataExtractor.cpp
parentff858d77810a5565a1f668c8e900a5e8659817be (diff)
downloadllvm-a16fffa3f6add51fe1c6ee975ace56aa06a3bea7.zip
llvm-a16fffa3f6add51fe1c6ee975ace56aa06a3bea7.tar.gz
llvm-a16fffa3f6add51fe1c6ee975ace56aa06a3bea7.tar.bz2
[Support] Make DataExtractor string functions error-aware
Summary: This patch adds an optional Error argument to DataExtractor functions for string extraction, and makes them behave like other DataExtractor functions (set the error if extraction fails, don't do anything if the error is already set). I have merged the StringRef and C string versions of the functions to reduce code duplication. Reviewers: dblaikie, MaskRay Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77307
Diffstat (limited to 'llvm/lib/Support/DataExtractor.cpp')
-rw-r--r--llvm/lib/Support/DataExtractor.cpp19
1 files changed, 7 insertions, 12 deletions
diff --git a/llvm/lib/Support/DataExtractor.cpp b/llvm/lib/Support/DataExtractor.cpp
index d6fd9a5..764c3fa 100644
--- a/llvm/lib/Support/DataExtractor.cpp
+++ b/llvm/lib/Support/DataExtractor.cpp
@@ -152,23 +152,18 @@ DataExtractor::getSigned(uint64_t *offset_ptr, uint32_t byte_size) const {
llvm_unreachable("getSigned unhandled case!");
}
-const char *DataExtractor::getCStr(uint64_t *offset_ptr) const {
- uint64_t offset = *offset_ptr;
- StringRef::size_type pos = Data.find('\0', offset);
- if (pos != StringRef::npos) {
- *offset_ptr = pos + 1;
- return Data.data() + offset;
- }
- return nullptr;
-}
+StringRef DataExtractor::getCStrRef(uint64_t *OffsetPtr, Error *Err) const {
+ ErrorAsOutParameter ErrAsOut(Err);
+ if (isError(Err))
+ return StringRef();
-StringRef DataExtractor::getCStrRef(uint64_t *offset_ptr) const {
- uint64_t Start = *offset_ptr;
+ uint64_t Start = *OffsetPtr;
StringRef::size_type Pos = Data.find('\0', Start);
if (Pos != StringRef::npos) {
- *offset_ptr = Pos + 1;
+ *OffsetPtr = Pos + 1;
return StringRef(Data.data() + Start, Pos - Start);
}
+ unexpectedEndReached(Err, Start);
return StringRef();
}