/// 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:
//------------------------------------------------------------------
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
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;
}
//------------------------------------------------------------------
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