summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgraham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2009-11-03 00:56:39 (EST)
committer graham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>2009-11-03 00:56:39 (EST)
commit74904d0ba19fca7f543fc2f2cde58ae9e371f9fd (patch)
treee9832d15468fe4ef082bc29924a6a5fc4b20a694
parent1918031b966a3bfbad57d02b6daa365e3b619883 (diff)
Clean up pkg_vec_insert.
- Check for realloc failure. - Don't cast an lvalue. - Remove unused counter. git-svn-id: http://opkg.googlecode.com/svn/trunk@247 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
-rw-r--r--libopkg/pkg_vec.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/libopkg/pkg_vec.c b/libopkg/pkg_vec.c
index 4c2200b..21ca23f 100644
--- a/libopkg/pkg_vec.c
+++ b/libopkg/pkg_vec.c
@@ -104,12 +104,16 @@ pkg_t *pkg_vec_insert_merge(pkg_vec_t *vec, pkg_t *pkg, int set_status,opkg_conf
}
}
-int pkg_vec_insert_called=0;
void pkg_vec_insert(pkg_vec_t *vec, const pkg_t *pkg)
{
- vec->pkgs = (pkg_t **)realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
- pkg_vec_insert_called++;
- *(const pkg_t **)&vec->pkgs[vec->len] = pkg;
+ pkg_t **tmp;
+ tmp = realloc(vec->pkgs, (vec->len + 1) * sizeof(pkg_t *));
+ if (tmp == NULL) {
+ fprintf(stderr, "%s: %s\n", __FUNCTION__, strerror(errno));
+ return;
+ }
+ vec->pkgs = tmp;
+ vec->pkgs[vec->len] = (pkg_t *)pkg;
vec->len++;
}