diff options
author | Timo Teräs <timo.teras@iki.fi> | 2010-06-05 12:06:41 +0300 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2010-06-05 12:33:54 +0300 |
commit | 7be853e63785276338a4c4d9e5be084f24114bed (patch) | |
tree | 3481293203a948897d7a10f9fb74f09a7c7d6286 | |
parent | 069c89898478b0273f7e6d0ea803d6151ee74ff7 (diff) | |
download | apk-tools-7be853e63785276338a4c4d9e5be084f24114bed.tar.gz apk-tools-7be853e63785276338a4c4d9e5be084f24114bed.tar.bz2 apk-tools-7be853e63785276338a4c4d9e5be084f24114bed.tar.xz apk-tools-7be853e63785276338a4c4d9e5be084f24114bed.zip |
all: rework how arrays work
Instead of having a null pointer, use a dummy array which just
says the array is empty. This helps in multiple places of the code
which would otherwise need explicitly need to check first if the
array exists. This has been cause of multiple seg.faults in the
past as the array check is easily omitted.
This also removes (or fixes) all existing checks accordingly.
-rw-r--r-- | src/Makefile | 2 | ||||
-rw-r--r-- | src/apk_defines.h | 36 | ||||
-rw-r--r-- | src/cache.c | 5 | ||||
-rw-r--r-- | src/common.c | 41 | ||||
-rw-r--r-- | src/database.c | 60 | ||||
-rw-r--r-- | src/del.c | 3 | ||||
-rw-r--r-- | src/fetch.c | 12 | ||||
-rw-r--r-- | src/fix.c | 2 | ||||
-rw-r--r-- | src/hash.c | 5 | ||||
-rw-r--r-- | src/index.c | 4 | ||||
-rw-r--r-- | src/info.c | 18 | ||||
-rw-r--r-- | src/package.c | 22 | ||||
-rw-r--r-- | src/search.c | 8 | ||||
-rw-r--r-- | src/state.c | 40 |
14 files changed, 137 insertions, 121 deletions
diff --git a/src/Makefile b/src/Makefile index 9f3249d..0f60fa9 100644 --- a/src/Makefile +++ b/src/Makefile @@ -5,7 +5,7 @@ $(error Build dependencies are not met) endif progs-y += apk -apk-objs := state.o database.o package.o archive.o \ +apk-objs := common.o state.o database.o package.o archive.o \ version.o io.o url.o gunzip.o blob.o hash.o apk.o \ add.o del.o fix.o update.o info.o search.o upgrade.o \ cache.o ver.o index.o fetch.o audit.o verify.o diff --git a/src/apk_defines.h b/src/apk_defines.h index 7414159..4a07414 100644 --- a/src/apk_defines.h +++ b/src/apk_defines.h @@ -1,7 +1,7 @@ /* apk_defines.c - Alpine Package Keeper (APK) * * Copyright (C) 2005-2008 Natanael Copa <n@tanael.org> - * Copyright (C) 2008 Timo Teräs <timo.teras@iki.fi> + * Copyright (C) 2008-2010 Timo Teräs <timo.teras@iki.fi> * All rights reserved. * * This program is free software; you can redistribute it and/or modify it @@ -12,7 +12,6 @@ #ifndef APK_DEFINES_H #define APK_DEFINES_H -#include <malloc.h> #include <string.h> #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) @@ -92,32 +91,33 @@ typedef void (*apk_progress_cb)(void *cb_ctx, size_t); #define APK_PROGRESS_SCALE 0x100 +void *apk_array_resize(void *array, size_t new_size, size_t elem_size); + #define APK_ARRAY(array_type_name, elem_type_name) \ struct array_type_name { \ int num; \ elem_type_name item[]; \ }; \ - static inline struct array_type_name * \ - array_type_name##_resize(struct array_type_name *a, int size) \ + static inline void \ + array_type_name##_init(struct array_type_name **a) \ + { \ + *a = apk_array_resize(NULL, 0, 0); \ + } \ + static inline void \ + array_type_name##_free(struct array_type_name **a) \ + { \ + *a = apk_array_resize(*a, 0, 0); \ + } \ + static inline void \ + array_type_name##_resize(struct array_type_name **a, size_t size)\ { \ - struct array_type_name *tmp; \ - int oldnum = a ? a->num : 0; \ - int diff = size - oldnum; \ - tmp = (struct array_type_name *) \ - realloc(a, sizeof(struct array_type_name) + \ - size * sizeof(elem_type_name)); \ - if (diff > 0) \ - memset(&tmp->item[oldnum], 0, \ - diff * sizeof(a->item[0])); \ - tmp->num = size; \ - return tmp; \ + *a = apk_array_resize(*a, size, sizeof(elem_type_name));\ } \ static inline elem_type_name * \ array_type_name##_add(struct array_type_name **a) \ { \ - int size = 1; \ - if (*a != NULL) size += (*a)->num; \ - *a = array_type_name##_resize(*a, size); \ + int size = 1 + (*a)->num; \ + *a = apk_array_resize(*a, size, sizeof(elem_type_name));\ return &(*a)->item[size-1]; \ } diff --git a/src/cache.c b/src/cache.c index 85d9777..4ed89fa 100644 --- a/src/cache.c +++ b/src/cache.c @@ -32,9 +32,6 @@ static int cache_download(struct apk_database *db) char item[PATH_MAX], cacheitem[PATH_MAX]; int i, r = 0; - if (db->world == NULL) - return 0; - state = apk_state_new(db); if (state == NULL) goto err; @@ -111,7 +108,7 @@ static int cache_clean(struct apk_database *db) } else { /* Package - search for it */ name = apk_db_get_name(db, bname); - if (name == NULL || name->pkgs == NULL) + if (name == NULL) break; for (i = 0; i < name->pkgs->num; i++) { struct apk_package *pkg = name->pkgs->item[i]; diff --git a/src/common.c b/src/common.c new file mode 100644 index 0000000..3eee2fb --- /dev/null +++ b/src/common.c @@ -0,0 +1,41 @@ +/* common.c - Alpine Package Keeper (APK) + * + * Copyright (C) 2010 Timo Teräs <timo.teras@iki.fi> + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. See http://www.gnu.org/ for details. + */ + +#include <malloc.h> +#include <string.h> +#include "apk_defines.h" + +static int *dummy_array = 0; + +void *apk_array_resize(void *array, size_t new_size, size_t elem_size) +{ + int old_size, diff; + void *tmp; + + if (new_size == 0) { + if (array != &dummy_array) + free(array); + return &dummy_array; + } + + old_size = array ? *((int*) array) : 0; + diff = new_size - old_size; + + if (array == &dummy_array) + array = NULL; + + tmp = realloc(array, sizeof(int) + new_size * elem_size); + if (diff > 0) + memset(tmp + sizeof(int) + old_size * elem_size, 0, + diff * elem_size); + *((int*) tmp) = new_size; + + return tmp; +} diff --git a/src/database.c b/src/database.c index 46ad98c..2e886c2 100644 --- a/src/database.c +++ b/src/database.c @@ -64,10 +64,8 @@ static apk_blob_t pkg_name_get_key(apk_hash_item item) static void pkg_name_free(struct apk_name *name) { free(name->name); - if (name->pkgs) - free(name->pkgs); - if (name->rdepends) - free(name->rdepends); + apk_package_array_free(&name->pkgs); + apk_name_array_free(&name->rdepends); free(name); } @@ -178,6 +176,8 @@ struct apk_name *apk_db_get_name(struct apk_database *db, apk_blob_t name) pn->name = apk_blob_cstr(name); pn->id = db->name_id++; + apk_package_array_init(&pn->pkgs); + apk_name_array_init(&pn->rdepends); apk_hash_insert_hashed(&db->available.names, pn, hash); return pn; @@ -382,17 +382,13 @@ static void apk_db_pkg_rdepends(struct apk_database *db, struct apk_package *pkg { int i, j; - if (pkg->depends == NULL) - return; - for (i = 0; i < pkg->depends->num; i++) { struct apk_name *rname = pkg->depends->item[i].name; - if (rname->rdepends) { - for (j = 0; j < rname->rdepends->num; j++) - if (rname->rdepends->item[j] == pkg->name) - return; - } + for (j = 0; j < rname->rdepends->num; j++) + if (rname->rdepends->item[j] == pkg->name) + return; + *apk_name_array_add(&rname->rdepends) = pkg->name; } } @@ -859,7 +855,8 @@ static void apk_db_triggers_read(struct apk_database *db, struct apk_bstream *bs ipkg = pkg->ipkg; apk_blob_for_each_segment(l, " ", parse_triggers, ipkg); - if (ipkg->triggers && !list_hashed(&ipkg->trigger_pkgs_list)) + if (ipkg->triggers->num != 0 && + !list_hashed(&ipkg->trigger_pkgs_list)) list_add_tail(&ipkg->trigger_pkgs_list, &db->installed.triggers); } @@ -887,7 +884,7 @@ static int apk_db_read_state(struct apk_database *db, int flags) apk_deps_parse(db, &db->world, blob); free(blob.ptr); - for (i = 0; db->world != NULL && i < db->world->num; i++) + for (i = 0; i < db->world->num; i++) db->world->item[i].name->flags |= APK_NAME_TOPLEVEL; } @@ -1046,6 +1043,8 @@ int apk_db_open(struct apk_database *db, struct apk_db_options *dbopts) apk_hash_init(&db->installed.files, &file_hash_ops, 10000); list_init(&db->installed.packages); list_init(&db->installed.triggers); + apk_dependency_array_init(&db->world); + apk_string_array_init(&db->protected_paths); db->cache_dir = apk_static_cache_dir; db->permanent = 1; @@ -1262,13 +1261,10 @@ void apk_db_close(struct apk_database *db) for (i = 0; i < db->num_repos; i++) { free(db->repos[i].url); } - if (db->protected_paths) { - for (i = 0; i < db->protected_paths->num; i++) - free(db->protected_paths->item[i]); - free(db->protected_paths); - } - if (db->world) - free(db->world); + for (i = 0; i < db->protected_paths->num; i++) + free(db->protected_paths->item[i]); + apk_dependency_array_free(&db->world); + apk_string_array_free(&db->protected_paths); apk_hash_free(&db->available.packages); apk_hash_free(&db->available.names); @@ -1309,10 +1305,10 @@ static int fire_triggers(apk_hash_item item, void *ctx) FNM_PATHNAME) != 0) continue; - if (ipkg->pending_triggers == NULL) + /* And place holder for script name */ + if (ipkg->pending_triggers->num == 0) *apk_string_array_add(&ipkg->pending_triggers) = NULL; - *apk_string_array_add(&ipkg->pending_triggers) = dbd->rooted_name; break; @@ -1329,14 +1325,13 @@ int apk_db_run_triggers(struct apk_database *db) apk_hash_foreach(&db->installed.dirs, fire_triggers, db); list_for_each_entry(ipkg, &db->installed.triggers, trigger_pkgs_list) { - if (ipkg->pending_triggers == NULL) + if (ipkg->pending_triggers->num == 0) continue; *apk_string_array_add(&ipkg->pending_triggers) = NULL; apk_ipkg_run_script(ipkg, db->root_fd, APK_SCRIPT_TRIGGER, ipkg->pending_triggers->item); - free(ipkg->pending_triggers); - ipkg->pending_triggers = NULL; + apk_string_array_free(&ipkg->pending_triggers); } return 0; @@ -1651,13 +1646,11 @@ static int read_info_line(void *_ctx, apk_blob_t line) if (apk_blob_compare(APK_BLOB_STR("replaces"), l) == 0) { apk_blob_for_each_segment(r, " ", parse_replaces, ctx); } else if (apk_blob_compare(APK_BLOB_STR("triggers"), l) == 0) { - if (ipkg->triggers) { - free(ipkg->triggers); - ipkg->triggers = NULL; - } + apk_string_array_resize(&ipkg->triggers, 0); apk_blob_for_each_segment(r, " ", parse_triggers, ctx->ipkg); - if (ctx->ipkg->triggers && !list_hashed(&ipkg->trigger_pkgs_list)) + if (ctx->ipkg->triggers->num != 0 && + !list_hashed(&ipkg->trigger_pkgs_list)) list_add_tail(&ipkg->trigger_pkgs_list, &db->installed.triggers); } else { @@ -2118,10 +2111,9 @@ int apk_db_install_pkg(struct apk_database *db, } ipkg->flags |= APK_IPKGF_RUN_ALL_TRIGGERS; - if (ipkg->triggers) { + if (ipkg->triggers->num != 0) { list_del(&ipkg->trigger_pkgs_list); - free(ipkg->triggers); - ipkg->triggers = NULL; + apk_string_array_free(&ipkg->triggers); } if (oldpkg != NULL && oldpkg != newpkg && oldpkg->ipkg != NULL) { @@ -33,9 +33,6 @@ static int del_main(void *ctx, struct apk_database *db, int argc, char **argv) struct apk_name *name; int i, r = 0; - if (db->world == NULL) - return 0; - for (i = 0; i < argc; i++) { name = apk_db_get_name(db, APK_BLOB_STR(argv[i])); name->flags &= ~APK_NAME_TOPLEVEL; diff --git a/src/fetch.c b/src/fetch.c index 67b3322..dc9bff2 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -205,7 +205,7 @@ static int fetch_main(void *ctx, struct apk_database *db, int argc, char **argv) } apk_state_unref(state); - } else if (dep.name->pkgs != NULL) { + } else { struct apk_package *pkg = NULL; for (j = 0; j < dep.name->pkgs->num; j++) @@ -215,13 +215,15 @@ static int fetch_main(void *ctx, struct apk_database *db, int argc, char **argv) == APK_VERSION_GREATER) pkg = dep.name->pkgs->item[j]; + if (pkg == NULL) { + apk_message("Unable to get '%s'", dep.name->name); + r = -1; + break; + } + r = fetch_package(fctx, db, pkg); if (r != 0) goto err; - } else { - apk_message("Unable to get '%s'", dep.name->name); - r = -1; - break; } } @@ -69,7 +69,7 @@ static int fix_main(void *pctx, struct apk_database *db, int argc, char **argv) apk_dep_from_blob(&deps[i], db, APK_BLOB_STR(argv[i])); name = deps[i].name; - for (j = 0; name->pkgs && j < name->pkgs->num; j++) { + for (j = 0; j < name->pkgs->num; j++) { if (name->pkgs->item[j]->ipkg != NULL) { pkg = name->pkgs->item[j]; break; @@ -16,14 +16,15 @@ void apk_hash_init(struct apk_hash *h, const struct apk_hash_ops *ops, int num_buckets) { h->ops = ops; - h->buckets = apk_hash_array_resize(NULL, num_buckets); + apk_hash_array_init(&h->buckets); + apk_hash_array_resize(&h->buckets, num_buckets); h->num_items = 0; } void apk_hash_free(struct apk_hash *h) { apk_hash_foreach(h, (apk_hash_enumerator_f) h->ops->delete_item, NULL); - free(h->buckets); + apk_hash_array_free(&h->buckets); } int apk_hash_foreach(struct apk_hash *h, apk_hash_enumerator_f e, void *ctx) diff --git a/src/index.c b/src/index.c index fffa739..2676269 100644 --- a/src/index.c +++ b/src/index.c @@ -72,7 +72,7 @@ static int warn_if_no_providers(apk_hash_item item, void *ctx) struct counts *counts = (struct counts *) ctx; struct apk_name *name = (struct apk_name *) item; - if (name->pkgs == NULL) { + if (name->pkgs->num == 0) { if (++counts->unsatisfied < 10) { apk_warning("No provider for dependency '%s'", name->name); @@ -139,7 +139,7 @@ static int index_main(void *ctx, struct apk_database *db, int argc, char **argv) /* If we have it in the old index already? */ name = apk_db_query_name(db, bname); - if (name == NULL || name->pkgs == NULL) + if (name == NULL) break; for (j = 0; j < name->pkgs->num; j++) { @@ -75,9 +75,6 @@ static int info_exists(struct info_ctx *ctx, struct apk_database *db, continue; name = dep.name; - if (name->pkgs == NULL) - continue; - for (j = 0; j < name->pkgs->num; j++) { pkg = name->pkgs->item[j]; if (pkg->ipkg != NULL) @@ -168,13 +165,10 @@ static void info_print_depends(struct apk_package *pkg) char *separator = apk_verbosity > 1 ? " " : "\n"; if (apk_verbosity == 1) printf("%s-%s depends on:\n", pkg->name->name, pkg->version); - if (pkg->depends == NULL) - return; if (apk_verbosity > 1) printf("%s: ", pkg->name->name); - for (i = 0; i < pkg->depends->num; i++) { + for (i = 0; i < pkg->depends->num; i++) printf("%s%s", pkg->depends->item[i].name->name, separator); - } } static void info_print_required_by(struct apk_package *pkg) @@ -184,8 +178,6 @@ static void info_print_required_by(struct apk_package *pkg) if (apk_verbosity == 1) printf("%s-%s is required by:\n", pkg->name->name, pkg->version); - if (pkg->name->rdepends == NULL) - return; if (apk_verbosity > 1) printf("%s: ", pkg->name->name); for (i = 0; i < pkg->name->rdepends->num; i++) { @@ -193,12 +185,10 @@ static void info_print_required_by(struct apk_package *pkg) /* Check only the package that is installed, and that * it actually has this package as dependency. */ - if (name0->pkgs == NULL) - continue; for (j = 0; j < name0->pkgs->num; j++) { struct apk_package *pkg0 = name0->pkgs->item[j]; - if (pkg0->ipkg == NULL || pkg0->depends == NULL) + if (pkg0->ipkg == NULL) continue; for (k = 0; k < pkg0->depends->num; k++) { if (pkg0->depends->item[k].name != pkg->name) @@ -240,7 +230,7 @@ static void info_print_triggers(struct apk_package *pkg) if (apk_verbosity == 1) printf("%s-%s triggers:\n", pkg->name->name, pkg->version); - for (i = 0; ipkg->triggers && i < ipkg->triggers->num; i++) { + for (i = 0; i < ipkg->triggers->num; i++) { if (apk_verbosity > 1) printf("%s: trigger ", pkg->name->name); printf("%s\n", ipkg->triggers->item[i]); @@ -283,7 +273,7 @@ static int info_package(struct info_ctx *ctx, struct apk_database *db, for (i = 0; i < argc; i++) { name = apk_db_query_name(db, APK_BLOB_STR(argv[i])); - if (name == NULL || name->pkgs == NULL) { + if (name == NULL || name->pkgs->num == 0) { apk_error("Not found: %s", argv[i]); return 1; } diff --git a/src/package.c b/src/package.c index cc79d05..f981f45 100644 --- a/src/package.c +++ b/src/package.c @@ -53,7 +53,13 @@ void apk_pkg_format_cache(struct apk_package *pkg, apk_blob_t to) struct apk_package *apk_pkg_new(void) { - return calloc(1, sizeof(struct apk_package)); + struct apk_package *pkg; + + pkg = calloc(1, sizeof(struct apk_package)); + if (pkg != NULL) + apk_dependency_array_init(&pkg->depends); + + return pkg; } struct apk_installed_package *apk_pkg_install(struct apk_database *db, @@ -66,6 +72,8 @@ struct apk_installed_package *apk_pkg_install(struct apk_database *db, pkg->ipkg = ipkg = calloc(1, sizeof(struct apk_installed_package)); ipkg->pkg = pkg; + apk_string_array_init(&ipkg->triggers); + apk_string_array_init(&ipkg->pending_triggers); /* Overlay override information resides in a nameless package */ if (pkg->name != NULL) { @@ -90,13 +98,14 @@ void apk_pkg_uninstall(struct apk_database *db, struct apk_package *pkg) list_del(&ipkg->installed_pkgs_list); - if (ipkg->triggers) { + if (ipkg->triggers->num) { list_del(&ipkg->trigger_pkgs_list); list_init(&ipkg->trigger_pkgs_list); for (i = 0; i < ipkg->triggers->num; i++) free(ipkg->triggers->item[i]); - free(ipkg->triggers); } + apk_string_array_free(&ipkg->triggers); + apk_string_array_free(&ipkg->pending_triggers); for (i = 0; i < APK_SCRIPT_MAX; i++) if (ipkg->script[i].ptr != NULL) @@ -180,7 +189,7 @@ void apk_deps_del(struct apk_dependency_array **pdeps, continue; deps->item[i] = deps->item[deps->num-1]; - *pdeps = apk_dependency_array_resize(deps, deps->num-1); + apk_dependency_array_resize(pdeps, deps->num-1); break; } } @@ -809,8 +818,7 @@ void apk_pkg_free(struct apk_package *pkg) return; apk_pkg_uninstall(NULL, pkg); - if (pkg->depends) - free(pkg->depends); + apk_dependency_array_free(&pkg->depends); if (pkg->version) free(pkg->version); if (pkg->url) @@ -970,7 +978,7 @@ int apk_pkg_write_index_entry(struct apk_package *info, if (os->write(os, bbuf.ptr, bbuf.len) != bbuf.len) return -1; - if (info->depends != NULL) { + if (info->depends->num > 0) { if (os->write(os, "D:", 2) != 2) return -1; r = apk_deps_write(info->depends, os); diff --git a/src/search.c b/src/search.c index e5e5d55..14eb0fb 100644 --- a/src/search.c +++ b/src/search.c @@ -45,18 +45,12 @@ static int print_rdepends(struct apk_package *pkg) int i, j, k; name = pkg->name; - if (name->rdepends == NULL) - return 0; printf("%s-%s:", pkg->name->name, pkg->version); for (i = 0; i < name->rdepends->num; i++) { name0 = name->rdepends->item[i]; - if (name0->pkgs == NULL) - continue; for (j = 0; j < name0->pkgs->num; j++) { pkg0 = name0->pkgs->item[j]; - if (pkg0->depends == NULL) - continue; for (k = 0; k < pkg0->depends->num; k++) { dep = &pkg0->depends->item[k]; if (name == dep->name && @@ -146,7 +140,7 @@ static int search_main(void *ctx, struct apk_database *db, int argc, char **argv } else { for (i = 0; i < argc; i++) { name = apk_db_query_name(db, APK_BLOB_STR(argv[i])); - if (name == NULL || name->pkgs == NULL) + if (name == NULL) continue; for (j = 0; j < name->pkgs->num; j++) ictx->print(name->pkgs->item[j]); diff --git a/src/state.c b/src/state.c index 141f466..4dd9c5b 100644 --- a/src/state.c +++ b/src/state.c @@ -105,7 +105,7 @@ static struct apk_name_choices *name_choices_new(struct apk_database *db, struct apk_name_choices *nc; int i, j; - if (name->pkgs == NULL) + if (name->pkgs->num == 0) return NULL; nc = malloc(sizeof(struct apk_name_choices) + @@ -122,7 +122,7 @@ static struct apk_name_choices *name_choices_new(struct apk_database *db, return nc; /* Check for global dependencies */ - for (i = 0; db->world != NULL && i < db->world->num; i++) { + for (i = 0; i < db->world->num; i++) { struct apk_dependency *dep = &db->world->item[i]; if (dep->name != name) @@ -198,6 +198,9 @@ struct apk_state *apk_state_new(struct apk_database *db) state->db = db; list_init(&state->change_list_head); + apk_name_array_init(&state->missing); + apk_package_array_init(&state->conflicts); + return state; } @@ -211,6 +214,9 @@ void apk_state_unref(struct apk_state *state) { if (--state->refs > 0) return; + + apk_package_array_free(&state->conflicts); + apk_name_array_free(&state->missing); free(state); } @@ -397,7 +403,7 @@ static int apk_state_fix_package(struct apk_state *state, { int i, r, ret = 0; - if (pkg == NULL || pkg->depends == NULL) + if (pkg == NULL) return 0; for (i = 0; i < pkg->depends->num; i++) { @@ -422,9 +428,6 @@ static int call_if_dependency_broke(struct apk_state *state, struct apk_package *dep_pkg; int k; - if (pkg->depends == NULL) - return 0; - dep_pkg = ns_to_pkg(state->name[dep_name->id]); for (k = 0; k < pkg->depends->num; k++) { struct apk_dependency *dep = &pkg->depends->item[k]; @@ -454,9 +457,6 @@ static int for_each_broken_reverse_depency(struct apk_state *state, struct apk_package *pkg0; int i, j, r; - if (name->rdepends == NULL) - return 0; - for (i = 0; i < name->rdepends->num; i++) { struct apk_name *name0 = name->rdepends->item[i]; @@ -536,14 +536,11 @@ int apk_state_lock_name(struct apk_state *state, ns_free(state->name[name->id]); state->name[name->id] = ns_from_pkg_non_pending(newpkg); - if (name->pkgs != NULL) { - for (i = 0; i < name->pkgs->num; i++) { - struct apk_package *pkg = name->pkgs->item[i]; - - if (name->pkgs->item[i]->name == name && - pkg->ipkg != NULL) - oldpkg = pkg; - } + for (i = 0; i < name->pkgs->num; i++) { + struct apk_package *pkg = name->pkgs->item[i]; + if (name->pkgs->item[i]->name == name && + pkg->ipkg != NULL) + oldpkg = pkg; } /* First we need to make sure the dependants of the old package @@ -766,9 +763,6 @@ static int apk_state_autoclean(struct apk_state *state, apk_name_state_t oldns; int i, r; - if (pkg->depends == NULL) - return 0; - for (i = 0; i < pkg->depends->num; i++) { struct apk_name *n = pkg->depends->item[i].name; @@ -831,14 +825,14 @@ void apk_state_print_errors(struct apk_state *state) struct error_state es; int i, j, r; - for (i = 0; state->conflicts != NULL && i < state->conflicts->num; i++) { + for (i = 0; i < state->conflicts->num; i++) { if (i == 0) apk_error("Unable to satisfy all dependencies:"); es.prevpkg = pkg = state->conflicts->item[i]; es.indent.x = es.indent.indent = printf(" %s-%s:", pkg->name->name, pkg->version); - for (j = 0; pkg->depends != NULL && j < pkg->depends->num; j++) { + for (j = 0; j < pkg->depends->num; j++) { r = apk_state_lock_dependency(state, &pkg->depends->item[j]); if (r != 0) @@ -851,7 +845,7 @@ void apk_state_print_errors(struct apk_state *state) printf("\n"); } - for (i = 0; state->missing != NULL && i < state->missing->num; i++) { + for (i = 0; i < state->missing->num; i++) { struct apk_name *name = state->missing->item[i]; if (i == 0) { apk_error("Missing packages:"); |