index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
author | Andrew Gregory <andrew.gregory.8@gmail.com> | 2018-01-07 19:30:42 -0500 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2018-01-10 10:52:26 +1000 |
commit | 2bda849bf9b39b423175d1ee1d8796b856cc9988 (patch) | |
tree | 457191f5eae040c3c37b152fe14dab275ff4c0af /lib/libalpm/pkghash.c | |
parent | 59b6fdeee1722a58d1599bcbd1e2c0fc33debc99 (diff) |
-rw-r--r-- | lib/libalpm/pkghash.c | 23 |
diff --git a/lib/libalpm/pkghash.c b/lib/libalpm/pkghash.c index 45e63082..a0e81f28 100644 --- a/lib/libalpm/pkghash.c +++ b/lib/libalpm/pkghash.c @@ -132,8 +132,7 @@ static alpm_pkghash_t *rehash(alpm_pkghash_t *oldhash) newhash = _alpm_pkghash_create(newsize); if(newhash == NULL) { - /* creation of newhash failed, stick with old one... */ - return oldhash; + return NULL; } newhash->list = oldhash->list; @@ -156,23 +155,29 @@ static alpm_pkghash_t *rehash(alpm_pkghash_t *oldhash) return newhash; } -static alpm_pkghash_t *pkghash_add_pkg(alpm_pkghash_t *hash, alpm_pkg_t *pkg, +static alpm_pkghash_t *pkghash_add_pkg(alpm_pkghash_t **hashref, alpm_pkg_t *pkg, int sorted) { alpm_list_t *ptr; unsigned int position; + alpm_pkghash_t *hash; - if(pkg == NULL || hash == NULL) { - return hash; + if(pkg == NULL || hashref == NULL || *hashref == NULL) { + return NULL; } + hash = *hashref; if(hash->entries >= hash->limit) { - hash = rehash(hash); + if((hash = rehash(hash)) == NULL) { + /* resizing failed and there are no more open buckets */ + return NULL; + } + *hashref = hash; } position = get_hash_position(pkg->name_hash, hash); - MALLOC(ptr, sizeof(alpm_list_t), return hash); + MALLOC(ptr, sizeof(alpm_list_t), return NULL); ptr->data = pkg; ptr->prev = ptr; @@ -189,12 +194,12 @@ static alpm_pkghash_t *pkghash_add_pkg(alpm_pkghash_t *hash, alpm_pkg_t *pkg, return hash; } -alpm_pkghash_t *_alpm_pkghash_add(alpm_pkghash_t *hash, alpm_pkg_t *pkg) +alpm_pkghash_t *_alpm_pkghash_add(alpm_pkghash_t **hash, alpm_pkg_t *pkg) { return pkghash_add_pkg(hash, pkg, 0); } -alpm_pkghash_t *_alpm_pkghash_add_sorted(alpm_pkghash_t *hash, alpm_pkg_t *pkg) +alpm_pkghash_t *_alpm_pkghash_add_sorted(alpm_pkghash_t **hash, alpm_pkg_t *pkg) { return pkghash_add_pkg(hash, pkg, 1); } |