summaryrefslogtreecommitdiffstats
path: root/src/info.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2010-06-05 12:06:41 +0300
committerTimo Teräs <timo.teras@iki.fi>2010-06-05 12:33:54 +0300
commit7be853e63785276338a4c4d9e5be084f24114bed (patch)
tree3481293203a948897d7a10f9fb74f09a7c7d6286 /src/info.c
parent069c89898478b0273f7e6d0ea803d6151ee74ff7 (diff)
downloadapk-tools-7be853e63785276338a4c4d9e5be084f24114bed.tar.bz2
apk-tools-7be853e63785276338a4c4d9e5be084f24114bed.tar.xz
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/info.c')
-rw-r--r--src/info.c18
1 files changed, 4 insertions, 14 deletions
diff --git a/src/info.c b/src/info.c
index d944fca..d6438cf 100644
--- a/src/info.c
+++ b/src/info.c
@@ -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;
}