Fixed the ValidOffsetForDataOfSize() to use simpler logic. Fixed DataExtractor::Bytes...
authorGreg Clayton <gclayton@apple.com>
Thu, 21 Mar 2013 00:29:45 +0000 (00:29 +0000)
committerGreg Clayton <gclayton@apple.com>
Thu, 21 Mar 2013 00:29:45 +0000 (00:29 +0000)
llvm-svn: 177616

lldb/include/lldb/Core/DataEncoder.h
lldb/include/lldb/Core/DataExtractor.h
lldb/source/Core/DataEncoder.cpp

index 20da546..658cce0 100644 (file)
@@ -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:
     //------------------------------------------------------------------
index 57c36d8..38dfd2f 100644 (file)
@@ -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;
     }
     
     //------------------------------------------------------------------
index 933cc3e..92a9104 100644 (file)
@@ -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