[PATCH] retrace: Fix off-by-one error in detection of intersecting regions.

Carl Worth cworth at cworth.org
Fri Aug 24 13:58:36 PDT 2012


The upperBound functions returns the first region beyond the region
containing the given address. So, to correctly use it here, we must
give it the last valid address of the current range, which is just
less than (address + size).
---

 Of course, subtracting 1 here doesn't necessarily yield an
 addressable address, but it does avoid passing an address beyond the
 current range. One could subtract 4 here instead, or whatever the
 minimum addressable granularity is.

 retrace/retrace_swizzle.cpp |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/retrace/retrace_swizzle.cpp b/retrace/retrace_swizzle.cpp
index 52d1d74..693fdfe 100644
--- a/retrace/retrace_swizzle.cpp
+++ b/retrace/retrace_swizzle.cpp
@@ -108,7 +108,7 @@ addRegion(unsigned long long address, void *buffer, unsigned long long size)
 
 #ifndef NDEBUG
     RegionMap::iterator start = lowerBound(address);
-    RegionMap::iterator stop = upperBound(address + size);
+    RegionMap::iterator stop = upperBound(address + size - 1);
     if (0) {
         // Forget all regions that intersect this new one.
         regionMap.erase(start, stop);
-- 
1.7.10



More information about the apitrace mailing list