[Lldb-commits] [lldb] r177616 - Fixed the ValidOffsetForDataOfSize() to use simpler logic. Fixed DataExtractor::BytesLeft() to return the correct value.

Greg Clayton gclayton at apple.com
Wed Mar 20 17:29:45 PDT 2013


Author: gclayton
Date: Wed Mar 20 19:29:45 2013
New Revision: 177616

URL: http://llvm.org/viewvc/llvm-project?rev=177616&view=rev
Log:
Fixed the ValidOffsetForDataOfSize() to use simpler logic. Fixed DataExtractor::BytesLeft() to return the correct value.


Modified:
    lldb/trunk/include/lldb/Core/DataEncoder.h
    lldb/trunk/include/lldb/Core/DataExtractor.h
    lldb/trunk/source/Core/DataEncoder.cpp

Modified: lldb/trunk/include/lldb/Core/DataEncoder.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/DataEncoder.h?rev=177616&r1=177615&r2=177616&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/DataEncoder.h (original)
+++ lldb/trunk/include/lldb/Core/DataEncoder.h Wed Mar 20 19:29:45 2013
@@ -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:
     //------------------------------------------------------------------

Modified: lldb/trunk/include/lldb/Core/DataExtractor.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/DataExtractor.h?rev=177616&r1=177615&r2=177616&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Core/DataExtractor.h (original)
+++ lldb/trunk/include/lldb/Core/DataExtractor.h Wed Mar 20 19:29:45 2013
@@ -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;
     }
     
     //------------------------------------------------------------------

Modified: lldb/trunk/source/Core/DataEncoder.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/DataEncoder.cpp?rev=177616&r1=177615&r2=177616&view=diff
==============================================================================
--- lldb/trunk/source/Core/DataEncoder.cpp (original)
+++ lldb/trunk/source/Core/DataEncoder.cpp Wed Mar 20 19:29:45 2013
@@ -142,32 +142,6 @@ DataEncoder::GetSharedDataOffset () cons
     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





More information about the lldb-commits mailing list