#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <strings.h> // ffs() lives here
#include "xmalloc.h"
#include "uid_db.h"
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;
*/
struct pat_node *np;
- np = xmalloc(sizeof(*np));
+ np = (struct pat_node *)xmalloc(sizeof(*np));
np->rec = rec;
rec->next = NULL;
return np;
}
/*** various helpers */
+#if 0
static inline int record_id_equal(struct uid_db_record const *r0,
struct uid_db_record const *r1)
{
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)
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;
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;
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);
}
*/
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;
/** 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.
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;