How have I managed to neglect until now to put all the subdirectory
[sgt/agedu] / index.c
diff --git a/index.c b/index.c
index db3d2b3..1cdb2ea 100644 (file)
--- a/index.c
+++ b/index.c
@@ -9,9 +9,6 @@
 
 #define alignof(typ) ( offsetof(struct { char c; typ t; }, t) )
 
-#define min(x,y) ((x)<(y) ? (x):(y))
-#define max(x,y) ((x)>(y) ? (x):(y))
-
 #define PADDING(x, mod) ( ((mod) - ((x) % (mod))) % (mod) )
 
 struct avlnode {
@@ -52,7 +49,7 @@ static int index_maxdepth(int nodecount)
 off_t index_initial_size(off_t currentsize, int nodecount)
 {
     currentsize += PADDING(currentsize, alignof(off_t));
-    currentsize += nodecount + sizeof(off_t);
+    currentsize += nodecount * sizeof(off_t);
     currentsize += PADDING(currentsize, alignof(struct avlnode));
 
     return currentsize;
@@ -269,7 +266,9 @@ void indexbuild_rebase(indexbuild *ib, void *t)
     ib->t = t;
     ib->nodes = (struct avlnode *)((unsigned char *)ib->nodes + diff);
     ib->roots = (off_t *)((unsigned char *)ib->roots + diff);
-    ib->currroot = (struct avlnode *)((unsigned char *)ib->currroot + diff);
+    if (ib->currroot)
+       ib->currroot = (struct avlnode *)
+           ((unsigned char *)ib->currroot + diff);
     ib->firstmutable = (struct avlnode *)((unsigned char *)ib->firstmutable + diff);
 }