Index: /trunk/src/VBox/Runtime/testcase/tstIprtList.cpp
===================================================================
--- /trunk/src/VBox/Runtime/testcase/tstIprtList.cpp	(revision 86618)
+++ /trunk/src/VBox/Runtime/testcase/tstIprtList.cpp	(revision 86619)
@@ -526,4 +526,15 @@
 }
 
+/** Returns an index that is safe from the removal thread. */
+static uint32_t MtTestSafeRandomIndex(MTTEST_LIST_TYPE<MTTEST_TYPE> *pTestList)
+{
+    uint32_t cItems = (uint32_t)pTestList->size();
+    if (cItems > MTTEST_ITEMS)
+        cItems -= MTTEST_ITEMS;
+    if (cItems < MTTEST_ITEMS_NOT_REMOVED)
+        cItems = MTTEST_ITEMS_NOT_REMOVED;
+    return RTRandU32Ex(0, cItems - 1);
+}
+
 /**
  * Thread for inserting items to a shared list.
@@ -539,5 +550,5 @@
     /* Insert new items in the middle of the list. */
     for (size_t i = 0; i < MTTEST_ITEMS; ++i)
-        pTestList->insert(pTestList->size() / 2, 0xF0F0F0F0);
+        pTestList->insert(MtTestSafeRandomIndex(pTestList), 0xF0F0F0F0);
 
     return VINF_SUCCESS;
@@ -562,6 +573,5 @@
         while (pTestList->isEmpty())
             RTThreadYield();
-        uint32_t const idx = RTRandU32Ex(0, RT_MIN((uint32_t)pTestList->size() / 2, MTTEST_ITEMS_NOT_REMOVED));
-        a = pTestList->at(idx);
+        a = pTestList->at(MtTestSafeRandomIndex(pTestList));
     }
 
@@ -586,6 +596,5 @@
         while (pTestList->isEmpty())
             RTThreadYield();
-        uint32_t const idx = RTRandU32Ex(0, RT_MIN((uint32_t)pTestList->size() / 2, MTTEST_ITEMS_NOT_REMOVED));
-        pTestList->replace(idx, 0xFF00FF00);
+        pTestList->replace(MtTestSafeRandomIndex(pTestList), 0xFF00FF00);
     }
 
