summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lldb/include/lldb/Core/DataEncoder.h14
-rw-r--r--lldb/include/lldb/Core/DataExtractor.h9
-rw-r--r--lldb/source/Core/DataEncoder.cpp26
3 files changed, 17 insertions, 32 deletions
diff --git a/lldb/include/lldb/Core/DataEncoder.h b/lldb/include/lldb/Core/DataEncoder.h
index 20da5468d34..658cce0d2b4 100644
--- a/lldb/include/lldb/Core/DataEncoder.h
+++ b/lldb/include/lldb/Core/DataEncoder.h
@@ -424,7 +424,19 @@ public:
/// length bytes available at that offset, \b false otherwise.
//------------------------------------------------------------------
bool
- ValidOffsetForDataOfSize (uint32_t offset, uint32_t length) const;
+ ValidOffsetForDataOfSize (uint32_t offset, uint32_t length) const
+ {
+ return length <= BytesLeft (offset);
+ }
+
+ uint32_t
+ BytesLeft (uint32_t offset) const
+ {
+ const uint32_t size = GetByteSize();
+ if (size > offset)
+ return size - offset;
+ return 0;
+ }
protected:
//------------------------------------------------------------------
diff --git a/lldb/include/lldb/Core/DataExtractor.h b/lldb/include/lldb/Core/DataExtractor.h
index 57c36d882e0..38dfd2f8370 100644
--- a/lldb/include/lldb/Core/DataExtractor.h
+++ b/lldb/include/lldb/Core/DataExtractor.h
@@ -1234,8 +1234,7 @@ public:
bool
ValidOffsetForDataOfSize (lldb::offset_t offset, lldb::offset_t length) const
{
- lldb::offset_t bytes_left = BytesLeft (offset);
- return length <= bytes_left;
+ return length <= BytesLeft (offset);
}
size_t
@@ -1253,9 +1252,9 @@ protected:
BytesLeft (lldb::offset_t offset) const
{
const lldb::offset_t size = GetByteSize();
- if (offset >= size)
- return 0;
- return offset - size;
+ if (size > offset)
+ return size - offset;
+ return 0;
}
//------------------------------------------------------------------
diff --git a/lldb/source/Core/DataEncoder.cpp b/lldb/source/Core/DataEncoder.cpp
index 933cc3eb23b..92a9104acc3 100644
--- a/lldb/source/Core/DataEncoder.cpp
+++ b/lldb/source/Core/DataEncoder.cpp
@@ -142,32 +142,6 @@ DataEncoder::GetSharedDataOffset () const
return 0;
}
-//------------------------------------------------------------------
-// Returns true if there are LENGTH bytes availabe starting OFFSET
-// into the data that is in this object.
-//------------------------------------------------------------------
-bool
-DataEncoder::ValidOffsetForDataOfSize (uint32_t offset, uint32_t length) const
-{
- size_t size = GetByteSize();
- if (offset >= size)
- return false; // offset isn't valid
-
- if (length == 0)
- return true; // No bytes requested at this offset, return true
-
- // If we flip the bits in offset we can figure out how
- // many bytes we have left before "offset + length"
- // could overflow when doing unsigned arithmetic.
- if (length > ~offset)
- return false; // unsigned overflow
-
- // Make sure "offset + length" is a valid offset as well.
- // length must be greater than zero for this to be a
- // valid expression, and we have already checked for this.
- return ((offset + length) <= size);
-}
-
//----------------------------------------------------------------------
// Set the data with which this object will extract from to data
// starting at BYTES and set the length of the data to LENGTH bytes
OpenPOWER on IntegriCloud