]> Pileus Git - ~andy/fetchmail/blobdiff - uid_db.c
Merge branch 'legacy_63'
[~andy/fetchmail] / uid_db.c
index 9648e01a11ae21916103ce6e4aca2290e01677de..14a081d8299b1262657bb6063942f9dab0e354eb 100644 (file)
--- a/uid_db.c
+++ b/uid_db.c
@@ -12,6 +12,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <strings.h>  // ffs() lives here
 
 #include "xmalloc.h"
 #include "uid_db.h"
@@ -72,7 +73,7 @@ static struct pat_node *walk_down(struct uid_db *db, struct uid_db_record *rec,
       This routine is intended for inserts only.
      */
     struct pat_node *cur, **edge;
-    unsigned bit_ndx, v, ofs;
+    unsigned bit_ndx, v = 0, ofs;
 
     cur = db->pat_root;
     ofs = -1;
@@ -173,7 +174,7 @@ static struct pat_node *get_pat_node(struct uid_db_record *rec)
     */
     struct pat_node *np;
 
-    np = xmalloc(sizeof(*np));
+    np = (struct pat_node *)xmalloc(sizeof(*np));
     np->rec = rec;
     rec->next = NULL;
     return np;
@@ -204,6 +205,7 @@ static struct pat_node *get_standalone_node(struct uid_db_record *rec)
 }
 
 /***  various helpers */
+#if 0
 static inline int record_id_equal(struct uid_db_record const *r0,
                                  struct uid_db_record const *r1)
 {
@@ -211,6 +213,7 @@ static inline int record_id_equal(struct uid_db_record const *r0,
        r0->id_len == r1->id_len
        && memcmp(r0->id, r1->id, r0->id_len) == 0;
 }
+#endif
 
 static struct uid_db_record *append_to_list(struct uid_db_record **recp,
                                            struct uid_db_record *rec)
@@ -290,10 +293,10 @@ static struct uid_db_record *get_uid_db_record(char const *id, unsigned status)
     struct uid_db_record *rec;
     size_t id_len;
 
-    rec = xmalloc(sizeof(*rec));
+    rec = (struct uid_db_record *)xmalloc(sizeof(*rec));
 
     id_len = strlen(id);
-    rec->id = memcpy(xmalloc(id_len + 1), id, id_len + 1);
+    rec->id = (char *)memcpy(xmalloc(id_len + 1), id, id_len + 1);
     rec->id_len = id_len;
     rec->status = status;
     rec->num = 0;
@@ -317,7 +320,7 @@ static void insert_into_records(struct uid_db *db,
 
     if (next == db->records_max) {
        want = db->records_max *= 2;
-       db->records = xrealloc(db->records, want * sizeof(rec));
+       db->records = (struct uid_db_record **)xrealloc(db->records, want * sizeof(rec));
     }
 
     rec->pos = next;
@@ -364,7 +367,7 @@ void set_uid_db_num(struct uid_db *db, struct uid_db_record *rec,
        want = num_ndx->pos_0_value - num + 1;
        num_ndx->end_value = num;
 
-       num_ndx->records = xrealloc(num_ndx->records, want * sizeof(rec));
+       num_ndx->records = (struct uid_db_record **)xrealloc(num_ndx->records, want * sizeof(rec));
        do num_ndx->records[--want] = NULL; while (want > have);
     }
 
@@ -410,7 +413,7 @@ struct uid_db_record *find_uid_by_id(struct uid_db *db, char const *id)
     */
     struct pat_node *np;
     struct uid_db_record *rec;
-    unsigned v, bit_ndx, ofs;
+    unsigned v = 0, bit_ndx, ofs;
     size_t len;
 
     np = db->pat_root;
@@ -457,6 +460,8 @@ struct uid_db_record *last_uid_in_db(struct uid_db *db, char const *id)
 /**  destruction */
 static void free_uid_list(struct uid_db_record *rec)
 {
+    if (!rec) return;
+
     /*
       Free the list of uid_db_records starting with
       the record pointed to by rec.
@@ -541,7 +546,7 @@ void init_uid_db(struct uid_db *db)
 
     db->pat_root = NULL;
 
-    db->records = xmalloc(MIN_RECORDS * sizeof(*db->records));
+    db->records = (struct uid_db_record **)xmalloc(MIN_RECORDS * sizeof(*db->records));
     db->records_max = MIN_RECORDS;
     db->records_next = 0;