From 74904d0ba19fca7f543fc2f2cde58ae9e371f9fd Mon Sep 17 00:00:00 2001 From: graham.gower Date: Tue, 03 Nov 2009 00:56:39 -0500 Subject: 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 --- 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++; } -- cgit v0.9.1