diff options
author | graham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358> | 2009-11-03 00:56:49 (EST) |
---|---|---|
committer | graham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358> | 2009-11-03 00:56:49 (EST) |
commit | fe5e98ee4104f8d192a0107e0e7bb3fddd582dbe (patch) | |
tree | d4117e15141eac6b589d3c3850db34f6a7409af9 | |
parent | 74904d0ba19fca7f543fc2f2cde58ae9e371f9fd (diff) |
Remove some code duplication, check for realloc failure.
git-svn-id: http://opkg.googlecode.com/svn/trunk@248 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
-rw-r--r-- | libopkg/pkg_vec.c | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/libopkg/pkg_vec.c b/libopkg/pkg_vec.c index 21ca23f..fa2c237 100644 --- a/libopkg/pkg_vec.c +++ b/libopkg/pkg_vec.c @@ -73,12 +73,9 @@ pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,opkg_conf /* we didn't find one, add it */ if (!found){ - opkg_message(conf, OPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n", + opkg_message(conf, OPKG_DEBUG2, "Function: %s. Adding new pkg=%s version=%s arch=%s\n", __FUNCTION__, pkg->name, pkg->version, pkg->architecture); - - vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *)); - vec->pkgs[vec->len] = pkg; - vec->len++; + pkg_vec_insert(vec, pkg); return pkg; } /* update the one that we have */ @@ -186,7 +183,13 @@ void abstract_pkg_vec_free(abstract_pkg_vec_t *vec) */ void abstract_pkg_vec_insert(abstract_pkg_vec_t *vec, abstract_pkg_t *pkg) { - vec->pkgs = (abstract_pkg_t **) realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *)); + abstract_pkg_t **tmp; + tmp = realloc(vec->pkgs, (vec->len + 1) * sizeof(abstract_pkg_t *)); + if (tmp == NULL) { + fprintf(stderr, "%s: %s\n", __FUNCTION__, strerror(errno)); + return; + } + vec->pkgs = tmp; vec->pkgs[vec->len] = pkg; vec->len++; } |