]> pd.if.org Git - btree/blobdiff - threadskv5.c
Fix small bug in main when there is less t han one input file
[btree] / threadskv5.c
index 544bb65de488065dc9310526cbfa7ac3d0543fc1..ec46ace3a3f7738d261fe9587ecf1ae7df7940d9 100644 (file)
@@ -2007,7 +2007,9 @@ BtVal *val;
        while( cnt++ < max ) {
                if( cnt == slot )
                        newslot = idx + 2;
-               if( cnt < max && slotptr(bt->frame,cnt)->dead )
+
+               if( cnt < max || page->lvl )
+                 if( slotptr(bt->frame,cnt)->dead )
                        continue;
 
                // copy the value across
@@ -2024,11 +2026,9 @@ BtVal *val;
 
                // make a librarian slot
 
-               if( idx ) {
-                       slotptr(page, ++idx)->off = nxt;
-                       slotptr(page, idx)->type = Librarian;
-                       slotptr(page, idx)->dead = 1;
-               }
+               slotptr(page, ++idx)->off = nxt;
+               slotptr(page, idx)->type = Librarian;
+               slotptr(page, idx)->dead = 1;
 
                // set up the slot
 
@@ -2144,7 +2144,8 @@ uint prev;
        idx = 0;
 
        while( cnt++ < max ) {
-               if( slotptr(set->page, cnt)->dead && cnt < max )
+               if( cnt < max || set->page->lvl )
+                 if( slotptr(set->page, cnt)->dead )
                        continue;
                src = valptr(set->page, cnt);
                nxt -= src->len + sizeof(BtVal);
@@ -2156,11 +2157,9 @@ uint prev;
 
                //      add librarian slot
 
-               if( idx ) {
-                       slotptr(bt->frame, ++idx)->off = nxt;
-                       slotptr(bt->frame, idx)->type = Librarian;
-                       slotptr(bt->frame, idx)->dead = 1;
-               }
+               slotptr(bt->frame, ++idx)->off = nxt;
+               slotptr(bt->frame, idx)->type = Librarian;
+               slotptr(bt->frame, idx)->dead = 1;
 
                //  add actual slot
 
@@ -2229,11 +2228,9 @@ uint prev;
 
                //      add librarian slot
 
-               if( idx ) {
-                       slotptr(set->page, ++idx)->off = nxt;
-                       slotptr(set->page, idx)->type = Librarian;
-                       slotptr(set->page, idx)->dead = 1;
-               }
+               slotptr(set->page, ++idx)->off = nxt;
+               slotptr(set->page, idx)->type = Librarian;
+               slotptr(set->page, idx)->dead = 1;
 
                //      add actual slot
 
@@ -2266,15 +2263,17 @@ uint prev;
        // insert new fence for reformulated left block of smaller keys
 
        bt_putid (value, set->page_no);
+       ptr = (BtKey*)fencekey;
 
-       if( bt_insertkey (bt, fencekey+1, *fencekey, lvl+1, value, BtId, 1) )
+       if( bt_insertkey (bt, ptr->key, ptr->len, lvl+1, value, BtId, 1) )
                return bt->err;
 
        // switch fence for right block of larger keys to new right page
 
        bt_putid (value, right->page_no);
+       ptr = (BtKey*)rightkey;
 
-       if( bt_insertkey (bt, rightkey+1, *rightkey, lvl+1, value, BtId, 1) )
+       if( bt_insertkey (bt, ptr->key, ptr->len, lvl+1, value, BtId, 1) )
                return bt->err;
 
        bt_unlockpage (BtLockParent, set->latch);