Automaked pazpar2. Bug #799. Preprocessor defines are put in cconfig.h and
[pazpar2-moved-to-github.git] / src / reclists.c
index 40f1d76..b9ac9f1 100644 (file)
@@ -1,9 +1,13 @@
 /*
- * $Id: reclists.c,v 1.1 2006-12-20 20:47:16 quinn Exp $
+ * $Id: reclists.c,v 1.3 2007-01-08 12:43:41 adam Exp $
  */
 
 #include <assert.h>
 
+#if HAVE_CONFIG_H
+#include <cconfig.h>
+#endif
+
 #include <yaz/yaz-util.h>
 
 #include "pazpar2.h"
@@ -71,7 +75,7 @@ struct record *reclist_insert(struct reclist *l, struct record  *record)
 {
     unsigned int bucket;
     struct reclist_bucket **p;
-    struct record *head;
+    struct record *head = 0;
 
     bucket = hash((unsigned char*) record->merge_key) & l->hashmask;
     for (p = &l->hashtable[bucket]; *p; p = &(*p)->next)
@@ -86,14 +90,18 @@ struct record *reclist_insert(struct reclist *l, struct record  *record)
             break;
         }
     }
-    if (!*p) // We made it to the end of the bucket without finding match
+    if (!head && l->num_records < l->flatlist_size)
     {
-        struct reclist_bucket *new = nmem_malloc(l->nmem,
-                sizeof(struct reclist_bucket));
+        struct reclist_bucket *new =
+            nmem_malloc(l->nmem, sizeof(struct reclist_bucket));
+        
+        assert(!*p);
+        
         new->record = record;
         record->next_cluster = 0;
         new->next = 0;
         *p = new;
+        assert(l->num_records < l->flatlist_size);
         l->flatlist[l->num_records++] = record;
         head = record;
     }