]> xenbits.xensource.com Git - people/pauldu/xenbus.git/commitdiff
Fix RangeSet cursor problem
authorPaul Durrant <paul.durrant@citrix.com>
Wed, 30 Apr 2014 10:47:01 +0000 (11:47 +0100)
committerPaul Durrant <paul.durrant@citrix.com>
Wed, 30 Apr 2014 11:31:03 +0000 (12:31 +0100)
When the last or first range in the set is removed then the cursor may end
up pointing back at the anchor point. This confused RangeSetPop() so we
need to make sure that the cursor wraps round when this happens, such that
the only valid reason for the cursor to ever point at the anchor is when
the set goes empty.

Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
src/xenbus/range_set.c

index c9cf637fca9dc73116434edcf4a62556e2efb879..4aa95e640e814d93be125c1b89fb7cb235e1e933 100644 (file)
@@ -37,8 +37,7 @@
 #include "dbg_print.h"
 #include "assert.h"
 
-//#define RANGE_SET_AUDIT DBG
-#define RANGE_SET_AUDIT 1
+#define RANGE_SET_AUDIT DBG
 
 #define RANGE_SET_TAG   'GNAR'
 
@@ -109,6 +108,9 @@ __RangeSetAudit(
         ULONGLONG   Count;
         PLIST_ENTRY ListEntry;
 
+        ASSERT3P(RangeSet->Cursor, !=, &RangeSet->List);
+        ASSERT3U(RangeSet->Count, !=, 0);
+
         FoundCursor = FALSE;
         Count = 0;
 
@@ -158,6 +160,9 @@ __RangeSetRemove(
 
     RemoveEntryList(Cursor);
 
+    if (RangeSet->Cursor == &RangeSet->List)
+        RangeSet->Cursor = (After) ? RangeSet->List.Flink : RangeSet->List.Blink;
+
     Range = CONTAINING_RECORD(Cursor, RANGE, ListEntry);
     ASSERT3S(Range->End, <, Range->Start);