[ntoskrnl/cm]
authorAleksey Bragin <aleksey@reactos.org>
Tue, 24 Nov 2009 22:56:43 +0000 (22:56 +0000)
committerAleksey Bragin <aleksey@reactos.org>
Tue, 24 Nov 2009 22:56:43 +0000 (22:56 +0000)
- CmpSelectLeaf fixes: looking into an incorrect cell, returning wrong cell, slightly simplify code and add more comments for clarity. Thanks to Michael Martin for spotting these bugs.

svn path=/trunk/; revision=44285

reactos/ntoskrnl/config/cmindex.c

index e489775..162263d 100644 (file)
@@ -1344,6 +1344,8 @@ CmpSelectLeaf(IN PHHIVE Hive,
                 *RootCell = &IndexKey->List[SubKeyIndex];
                 return LeafCell;
             }
                 *RootCell = &IndexKey->List[SubKeyIndex];
                 return LeafCell;
             }
+
+            /* It didn't fit, so proceed to splitting */
         }
         else
         {
         }
         else
         {
@@ -1380,22 +1382,22 @@ CmpSelectLeaf(IN PHHIVE Hive,
             /* Check if it's above */
             if (Result >= 0)
             {
             /* Check if it's above */
             if (Result >= 0)
             {
-                /* Get the first cell in the index */
-                LeafCell = IndexKey->List[0];
+                /* Get the cell in the index */
+                LeafCell = IndexKey->List[SubKeyIndex];
                 LeafKey = (PCM_KEY_INDEX)HvGetCell(Hive, LeafCell);
 
                 /* Return an error in case of problems */
                 if (!LeafKey) return HCELL_NIL;
 
                 LeafKey = (PCM_KEY_INDEX)HvGetCell(Hive, LeafCell);
 
                 /* Return an error in case of problems */
                 if (!LeafKey) return HCELL_NIL;
 
-                /* Check if it fits into this leaf and break */
+                /* Check if it fits into this leaf */
                 if (LeafKey->Count < CmpMaxIndexPerHblock)
                 {
                     /* Fill in the result and return the cell */
                 if (LeafKey->Count < CmpMaxIndexPerHblock)
                 {
                     /* Fill in the result and return the cell */
-                    *RootCell = &IndexKey->List[SubKeyIndex + 1];
+                    *RootCell = &IndexKey->List[SubKeyIndex];
                     return LeafCell;
                 }
 
                     return LeafCell;
                 }
 
-                /* No, it doesn't fit, check the other leaf */
+                /* No, it doesn't fit, check the next adjacent leaf */
                 if (SubKeyIndex < (IndexKey->Count - 1))
                 {
                     /* Yes, there is space */
                 if (SubKeyIndex < (IndexKey->Count - 1))
                 {
                     /* Yes, there is space */
@@ -1413,6 +1415,8 @@ CmpSelectLeaf(IN PHHIVE Hive,
                         return LeafCell;
                     }
                 }
                         return LeafCell;
                     }
                 }
+
+                /* It didn't fit, so proceed to splitting */
             }
             else
             {
             }
             else
             {
@@ -1429,11 +1433,8 @@ CmpSelectLeaf(IN PHHIVE Hive,
                     /* Check if it fits and break */
                     if (LeafKey->Count < CmpMaxIndexPerHblock)
                     {
                     /* Check if it fits and break */
                     if (LeafKey->Count < CmpMaxIndexPerHblock)
                     {
-                        /* Decrement the subkey index */
-                        SubKeyIndex--;
-
                         /* Fill in the result and return the cell */
                         /* Fill in the result and return the cell */
-                        *RootCell = &IndexKey->List[SubKeyIndex];
+                        *RootCell = &IndexKey->List[SubKeyIndex - 1];
                         return LeafCell;
                     }
                 }
                         return LeafCell;
                     }
                 }