summaryrefslogtreecommitdiffstats
path: root/xtables.c
diff options
context:
space:
mode:
authorJan Engelhardt <jengelh@medozas.de>2011-01-08 02:10:52 +0100
committerJan Engelhardt <jengelh@medozas.de>2011-01-08 02:10:52 +0100
commit1dc27393b7ba401e6228a5ee2472a6eb72836c43 (patch)
treed409036fdffbf2b41db9e2f79944e9851fbc1ae4 /xtables.c
parent5b1fecc7d017df093db7c667bcd1718e45b1df67 (diff)
xtables: reorder num_old substraction for clarity
When going over this again, I noticed we happen to malloc too much. That is no problem, but I felt moving the num_old adjustment upwards makes things more clear, and also addresses the allocation. Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
Diffstat (limited to 'xtables.c')
-rw-r--r--xtables.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/xtables.c b/xtables.c
index 566b5c3b..b6309010 100644
--- a/xtables.c
+++ b/xtables.c
@@ -95,6 +95,13 @@ struct option *xtables_merge_options(struct option *orig_opts,
for (num_old = 0; oldopts[num_old].name; num_old++) ;
for (num_new = 0; newopts[num_new].name; num_new++) ;
+ /*
+ * Since @oldopts also has @orig_opts already (and does so at the
+ * start), skip these entries.
+ */
+ oldopts += num_oold;
+ num_old -= num_oold;
+
merge = malloc(sizeof(*mp) * (num_oold + num_old + num_new + 1));
if (merge == NULL)
return NULL;
@@ -103,10 +110,6 @@ struct option *xtables_merge_options(struct option *orig_opts,
memcpy(merge, orig_opts, sizeof(*mp) * num_oold);
mp = merge + num_oold;
- /* Since @opts also has @orig_opts already, skip the entries */
- oldopts += num_oold;
- num_old -= num_oold;
-
/* Second, the new options */
xt_params->option_offset += 256;
*option_offset = xt_params->option_offset;