]> git.deb.at Git - pkg/abook.git/blobdiff - database.c
- replace abook_malloc, abook_realloc and my_free with new xmalloc routines
[pkg/abook.git] / database.c
index cf4f96632176f61604c8ffb5db5fb74b3783cfc4..5da2e93eced4b440c54ac3accaa2713d9a92d264 100644 (file)
@@ -19,6 +19,7 @@
 #include "misc.h"
 #include "options.h"
 #include "filter.h"
+#include "xmalloc.h"
 #ifdef HAVE_CONFIG_H
 #      include "config.h"
 #endif
@@ -223,7 +224,7 @@ free_list_item(list_item item)
        int i;
 
        for(i=0; i<ITEM_FIELDS; i++)
-               my_free(item[i]);
+               xfree(item[i]);
 }
 
 void
@@ -278,9 +279,8 @@ adjust_list_capacity()
        else
                return;
 
-       database = (list_item *)abook_realloc(database,
-                       sizeof(list_item) * list_capacity);
-       selected = (char *)abook_realloc(selected, list_capacity);
+       database = xrealloc(database, sizeof(list_item) * list_capacity);
+       selected = xrealloc(selected, list_capacity);
 }
 
 int
@@ -454,7 +454,7 @@ find_item(char *str, int start, int search_fields[])
                                ret = e.item;
                                goto out;
                        }
-                       my_free(tmp);
+                       xfree(tmp);
                }
        }
 
@@ -524,14 +524,17 @@ assign_fieldname(const char *name, int i)
 {
        char *s;
 
+       assert(name);
+       assert(i >= 0 && i < ITEM_FIELDS);
+
        if(strcasecmp(abook_fields[i].name, name)) { /* name differs */
                /*
                 * check if we are overwriting statically allocated default
                 */
                if(strcasecmp(abook_fields[i].name, abook_fields[i].key))
-                       my_free(abook_fields[i].name);
+                       xfree(abook_fields[i].name);
                
-               s = abook_malloc(MAX_FIELDNAME_LEN + 1);
+               s = xmalloc_inc(MAX_FIELDNAME_LEN, 1);
                snprintf(s, MAX_FIELDNAME_LEN, "%s", name);
                abook_fields[i].name = s;
        }
@@ -545,6 +548,8 @@ change_custom_field_name(const char *name, int n)
        int i;
        char keyname[21];
 
+       assert(name);
+
        snprintf(keyname, sizeof(keyname), "custom%d", n);
 
        for(i = CUSTOM_MIN; i <= CUSTOM_MAX; i++) {