summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
authorAaron Griffin <aaron@archlinux.org>2007-01-23 01:34:58 +0000
committerAaron Griffin <aaron@archlinux.org>2007-01-23 01:34:58 +0000
commit4db24ca28a31d1d0d97b30b186fd5255a0ae0113 (patch)
tree0ffe8319426d9ad84a6563883c445fc0fa0d6f40 /lib/libalpm
parent2a8b835dda8cf38636cad618bc01b433ef9eefa5 (diff)
* Added some calloc calls to replace the malloc-then-set-to-zero functionality
* Fixed -Ss output so as not to call alpm_list_getdata with a NULl list * Added a NULL check in alpm_list_getdata * Fixed alpm_list_add_sorted to properly handle a new / beginning insertions
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/alpm_list.c5
-rw-r--r--lib/libalpm/db.c8
-rw-r--r--lib/libalpm/group.c5
3 files changed, 7 insertions, 11 deletions
diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c
index a43f8211..26fcb3dc 100644
--- a/lib/libalpm/alpm_list.c
+++ b/lib/libalpm/alpm_list.c
@@ -145,8 +145,10 @@ alpm_list_t *alpm_list_add_sorted(alpm_list_t *list, void *data, alpm_list_fn_cm
if(prev != NULL) {
prev->next = add; /* In middle. */
+ } else {
+ list = add; /* At beginning, or new list */
}
-
+
return(list);
}
}
@@ -369,6 +371,7 @@ alpm_list_t *alpm_list_last(alpm_list_t *list)
*/
void *alpm_list_getdata(const alpm_list_t *entry)
{
+ if(entry == NULL) return(NULL);
return(entry->data);
}
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index 84c05ccc..363ce2a5 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -55,14 +55,14 @@ pmdb_t *_alpm_db_new(char *root, char* dbpath, char *treename)
{
pmdb_t *db;
- db = (pmdb_t *)malloc(sizeof(pmdb_t));
+ db = calloc(1, sizeof(pmdb_t));
if(db == NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failed: could not allocate %d bytes"),
sizeof(pmdb_t));
RET_ERR(PM_ERR_MEMORY, NULL);
}
- db->path = (char *)malloc(strlen(root)+strlen(dbpath)+strlen(treename)+2);
+ db->path = calloc(1, strlen(root)+strlen(dbpath)+strlen(treename)+2);
if(db->path == NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failed: could not allocate %d bytes"),
strlen(root)+strlen(dbpath)+strlen(treename)+2);
@@ -73,10 +73,6 @@ pmdb_t *_alpm_db_new(char *root, char* dbpath, char *treename)
STRNCPY(db->treename, treename, PATH_MAX);
- db->pkgcache = NULL;
- db->grpcache = NULL;
- db->servers = NULL;
-
return(db);
}
diff --git a/lib/libalpm/group.c b/lib/libalpm/group.c
index e0294ccb..3ec6338c 100644
--- a/lib/libalpm/group.c
+++ b/lib/libalpm/group.c
@@ -36,16 +36,13 @@ pmgrp_t *_alpm_grp_new()
{
pmgrp_t* grp;
- grp = (pmgrp_t *)malloc(sizeof(pmgrp_t));
+ grp = calloc(1, sizeof(pmgrp_t));
if(grp == NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"),
sizeof(pmgrp_t));
RET_ERR(PM_ERR_MEMORY, NULL);
}
- grp->name[0] = '\0';
- grp->packages = NULL;
-
return(grp);
}