about summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorDaniel Schemmel <daniel@schemmel.net>2023-06-29 01:13:26 +0000
committerCristian Cadar <c.cadar@imperial.ac.uk>2023-07-06 23:35:46 +0200
commit1fb67ef82f2d1e79a2cdb9d12bf05b3514dd45a3 (patch)
tree171fb6b888ea9f08b2d764d923005041e91d1ad6
parent3734251539d2192aafa938c530fa8eb45e48ecef (diff)
downloadklee-1fb67ef82f2d1e79a2cdb9d12bf05b3514dd45a3.tar.gz
Implement getLocationInfo in the same style as getSize
-rw-r--r--include/klee/KDAlloc/suballocators/sized_regions.h49
1 files changed, 21 insertions, 28 deletions
diff --git a/include/klee/KDAlloc/suballocators/sized_regions.h b/include/klee/KDAlloc/suballocators/sized_regions.h
index d8dafa86..8683f4d9 100644
--- a/include/klee/KDAlloc/suballocators/sized_regions.h
+++ b/include/klee/KDAlloc/suballocators/sized_regions.h
@@ -197,41 +197,34 @@ public:
 
     Node const *currentNode = root.get();
     Node const *closestPredecessor = nullptr;
-    for (;;) {
-      if (currentNode->getBaseAddress() <= address) {
+    while (currentNode) {
+      if (address < currentNode->getBaseAddress()) {
+        if (address + size > currentNode->getBaseAddress()) {
+          return LocationInfo::LI_Unaligned;
+        }
+        currentNode = currentNode->lhs.get();
+      } else {
         if (address < currentNode->getBaseAddress() + currentNode->getSize()) {
-          if (address + size <=
+          if (address + size >
               currentNode->getBaseAddress() + currentNode->getSize()) {
-            return LocationInfo::LI_Unallocated;
-          } else {
             return LocationInfo::LI_Unaligned;
+          } else {
+            return LocationInfo::LI_Unallocated;
           }
-        } else {
-          closestPredecessor = currentNode;
-          if (!currentNode->rhs) {
-            return {LocationInfo::LI_AllocatedOrQuarantined,
-                    closestPredecessor->getBaseAddress() +
-                        closestPredecessor->getSize()};
-          }
-          currentNode = currentNode->rhs.get();
-        }
-      } else {
-        assert(closestPredecessor &&
-               "If there is no closest predecessor, there must not be a "
-               "predecessor at all. Since regions are only ever split, "
-               "this would mean that the lookup is outside the valid "
-               "range, which has to be handled by the caller.");
-        if (currentNode->getBaseAddress() < address + size) {
-          return LocationInfo::LI_Unaligned;
-        }
-        if (!currentNode->lhs) {
-          return {LocationInfo::LI_AllocatedOrQuarantined,
-                  closestPredecessor->getBaseAddress() +
-                      closestPredecessor->getSize()};
         }
-        currentNode = currentNode->lhs.get();
+        assert(!closestPredecessor || currentNode->getBaseAddress() >
+                                          closestPredecessor->getBaseAddress());
+        closestPredecessor = currentNode;
+        currentNode = currentNode->rhs.get();
       }
     }
+
+    assert(closestPredecessor && "the caller must ensure that the requested "
+                                 "address is in range of the sized region");
+
+    return {LocationInfo::LI_AllocatedOrQuarantined,
+            closestPredecessor->getBaseAddress() +
+                closestPredecessor->getSize()};
   }
 
   void insert(char *const baseAddress, std::size_t const size) {