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 /src/package.c | |
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.
Diffstat (limited to 'src/package.c')
-rw-r--r-- | src/package.c | 22 |
1 files changed, 15 insertions, 7 deletions
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); |