* 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
This commit is contained in:
Aaron Griffin 2007-01-23 01:34:58 +00:00
parent 2a8b835dda
commit 4db24ca28a
4 changed files with 23 additions and 18 deletions

View file

@ -145,8 +145,10 @@ alpm_list_t *alpm_list_add_sorted(alpm_list_t *list, void *data, alpm_list_fn_cm
if(prev != NULL) { if(prev != NULL) {
prev->next = add; /* In middle. */ prev->next = add; /* In middle. */
} else {
list = add; /* At beginning, or new list */
} }
return(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) void *alpm_list_getdata(const alpm_list_t *entry)
{ {
if(entry == NULL) return(NULL);
return(entry->data); return(entry->data);
} }

View file

@ -55,14 +55,14 @@ pmdb_t *_alpm_db_new(char *root, char* dbpath, char *treename)
{ {
pmdb_t *db; pmdb_t *db;
db = (pmdb_t *)malloc(sizeof(pmdb_t)); db = calloc(1, sizeof(pmdb_t));
if(db == NULL) { if(db == NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failed: could not allocate %d bytes"), _alpm_log(PM_LOG_ERROR, _("malloc failed: could not allocate %d bytes"),
sizeof(pmdb_t)); sizeof(pmdb_t));
RET_ERR(PM_ERR_MEMORY, NULL); 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) { if(db->path == NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failed: could not allocate %d bytes"), _alpm_log(PM_LOG_ERROR, _("malloc failed: could not allocate %d bytes"),
strlen(root)+strlen(dbpath)+strlen(treename)+2); 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); STRNCPY(db->treename, treename, PATH_MAX);
db->pkgcache = NULL;
db->grpcache = NULL;
db->servers = NULL;
return(db); return(db);
} }

View file

@ -36,16 +36,13 @@ pmgrp_t *_alpm_grp_new()
{ {
pmgrp_t* grp; pmgrp_t* grp;
grp = (pmgrp_t *)malloc(sizeof(pmgrp_t)); grp = calloc(1, sizeof(pmgrp_t));
if(grp == NULL) { if(grp == NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"), _alpm_log(PM_LOG_ERROR, _("malloc failure: could not allocate %d bytes"),
sizeof(pmgrp_t)); sizeof(pmgrp_t));
RET_ERR(PM_ERR_MEMORY, NULL); RET_ERR(PM_ERR_MEMORY, NULL);
} }
grp->name[0] = '\0';
grp->packages = NULL;
return(grp); return(grp);
} }

View file

@ -248,14 +248,20 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
continue; continue;
} }
for(j = ret; j; j = alpm_list_next(j)) { for(j = ret; j; j = alpm_list_next(j)) {
char *group = NULL;
alpm_list_t *grp;
pmpkg_t *pkg = alpm_list_getdata(j); pmpkg_t *pkg = alpm_list_getdata(j);
char *group = (char *)alpm_list_getdata(alpm_pkg_get_groups(pkg)); printf("%s/%s %s", alpm_db_get_name(db), alpm_pkg_get_name(pkg),
printf("%s/%s %s %s%s%s\n ", alpm_pkg_get_version(pkg));
alpm_db_get_name(db),
alpm_pkg_get_name(pkg), if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
alpm_pkg_get_version(pkg), group = alpm_list_getdata(grp);
(group ? " (" : ""), (group ? group : ""), (group ? ") " : "")); printf(" (%s)\n ", (char *)alpm_list_getdata(grp));
} else {
printf("\n ");
}
indentprint(alpm_pkg_get_desc(pkg), 4); indentprint(alpm_pkg_get_desc(pkg), 4);
printf("\n\n"); printf("\n\n");
} }
@ -280,9 +286,12 @@ static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets)
if(targets) { if(targets) {
for(i = targets; i; i = alpm_list_next(i)) { for(i = targets; i; i = alpm_list_next(i)) {
char *grpname = alpm_list_getdata(i);
for(j = syncs; j; j = alpm_list_next(j)) { for(j = syncs; j; j = alpm_list_next(j)) {
pmdb_t *db = alpm_list_getdata(j); pmdb_t *db = alpm_list_getdata(j);
pmgrp_t *grp = alpm_db_readgrp(db, alpm_list_getdata(i)); printf("searching '%s' for groups '%s'\n", alpm_db_get_name(db), grpname);
fflush(stdout);
pmgrp_t *grp = alpm_db_readgrp(db, grpname);
if(grp) { if(grp) {
MSG(NL, "%s\n", (char *)alpm_grp_get_name(grp)); MSG(NL, "%s\n", (char *)alpm_grp_get_name(grp));