summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis R. Rodriguez <lrodriguez@atheros.com>2008-10-29 03:32:07 -0700
committerLuis R. Rodriguez <lrodriguez@atheros.com>2008-10-29 03:32:07 -0700
commit9fb08d3382fce0cfcc3f3b831bb7e827b1b5c547 (patch)
tree5ed2c947436af02f502f23fcd8ab3c57ed7a45c5
parent6bacea924b298741dc991c9f63e01452ee4537ea (diff)
downloadcrda-9fb08d3382fce0cfcc3f3b831bb7e827b1b5c547.tar.gz
crda-9fb08d3382fce0cfcc3f3b831bb7e827b1b5c547.tar.bz2
crda-9fb08d3382fce0cfcc3f3b831bb7e827b1b5c547.zip
Make intersection logic a bit more readable
Signed-off-by: Luis R. Rodriguez <lrodriguez@atheros.com>
-rw-r--r--intersect.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/intersect.c b/intersect.c
index 7a470e9..a8f9919 100644
--- a/intersect.c
+++ b/intersect.c
@@ -236,23 +236,6 @@ int main(int argc, char **argv)
if (is_world_regdom((const char *) country->alpha2))
continue;
- /* this is the previous country's rd, we don't care about it, we
- * only care about the resulting intersected world rd, which
- * should now be stored in prev_world, so we update that here */
- if (rd) {
- printf("Address of rd 2: %p -- about to free\n", (void *) rd);
- free(rd);
- printf("Address of rd 3: %p -- freed!\n", (void *) rd);
- rd = NULL;
-
- BUG_ON(!world);
-
- prev_world = world;
- world = NULL;
- } /* else prev_world is set correctly, first run,
- * it was set to the first valid rd which is not
- * the world regdomain, no need to update it */
-
/* Gets the rd for the current country */
rd = country2rd(db, dblen, country);
if (!rd) {
@@ -262,17 +245,32 @@ int main(int argc, char **argv)
goto out;
}
- printf("Address of rd 1: %p -- new allocation\n", (void *) rd);
+ if (num_countries == 1) {
+ world = rd;
+ rd = NULL;
+ break;
+ }
/* On our first iteration on the first valid rd for a country
* we take that rd as the first world regdomain.
* We only hit this on our first iteration of a valid rd */
if (!prev_world) {
prev_world = rd;
- rd = NULL;
continue;
}
+
+ /* this is the previous country's rd, we don't care about it, we
+ * only care about the resulting intersected world rd, which
+ * should now be stored in prev_world, so we update that here */
+ if (world) {
+ free(prev_world);
+ prev_world = world;
+ } /* else prev_world is set correctly, first run,
+ * it was set to the first valid rd which is not
+ * the world regdomain, no need to update it */
+
+
/* If this is our first time around prev_world is
* the first regdomain, and rd is the second. If
* this is our third time around prev_world is the
@@ -317,19 +315,21 @@ int main(int argc, char **argv)
if (intersected > 1)
printf("%d regulatory domains intersected\n", intersected);
else
- printf("Only one regulatory domain found\n");
+ printf("Only one intersection completed\n");
/* Tada! */
printf("== World regulatory domain: ==\n");
print_regdom(world);
out:
- if (world)
+ if (!intersected) {
free(world);
- if (rd)
+ return r;
+ }
+ if (intersected > 1) {
free(rd);
- if (prev_world)
free(prev_world);
-
+ }
+ free(world);
return r;
}