Clean up pkg_vec_insert.
authorgraham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Tue, 3 Nov 2009 05:56:39 +0000 (05:56 +0000)
committergraham.gower <graham.gower@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358>
Tue, 3 Nov 2009 05:56:39 +0000 (05:56 +0000)
- 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

libopkg/pkg_vec.c

index 4c2200b..21ca23f 100644 (file)
@@ -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++;
 }