netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: holger@eitzenberger.org
To: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Cc: netfilter-devel@vger.kernel.org
Subject: [patch 1/2] ipset: remove the unneeded argvloop
Date: Wed, 19 Jan 2011 21:26:08 +0100	[thread overview]
Message-ID: <20110119203559.494912348@eitzenberger.org> (raw)
In-Reply-To: 20110119202607.532407993@eitzenberger.org

[-- Attachment #1: ipset-enforce-command-order.diff --]
[-- Type: text/plain, Size: 3471 bytes --]

Remove the inner argv[] loop.

It is not a change functionality.

Signed-off-by: Holger Eitzenberger <holger@eitzenberger.org>

Index: ipset/src/ipset.c
===================================================================
--- ipset.orig/src/ipset.c	2011-01-19 21:14:59.000000000 +0100
+++ ipset/src/ipset.c	2011-01-19 21:17:55.000000000 +0100
@@ -425,7 +425,6 @@
 {
 	int ret = 0;
 	enum ipset_cmd cmd = IPSET_CMD_NONE;
-	int i;
 	char *arg0 = NULL, *arg1 = NULL, *c;
 	const struct ipset_envopts *opt;
 	const struct ipset_commands *command;
@@ -476,61 +475,58 @@
 
 	/* Second: parse command */
 	for (command = ipset_commands;
-	     command->cmd && cmd == IPSET_CMD_NONE;
+	     argc > 1 && command->cmd && cmd == IPSET_CMD_NONE;
 	     command++) {
-		for (i = 1; i < argc; ) {
-			if (!ipset_match_cmd(argv[1], command->name)) {
-				i++;
+		if (!ipset_match_cmd(argv[1], command->name))
 				continue;
-			}
-			if (restore_line != 0
-			    && (command->cmd == IPSET_CMD_RESTORE
-			    	|| command->cmd == IPSET_CMD_VERSION
-			    	|| command->cmd == IPSET_CMD_HELP))
-				return exit_error(PARAMETER_PROBLEM,
+
+		if (restore_line != 0
+			&& (command->cmd == IPSET_CMD_RESTORE
+				|| command->cmd == IPSET_CMD_VERSION
+				|| command->cmd == IPSET_CMD_HELP))
+			return exit_error(PARAMETER_PROBLEM,
 					"Command `%s' is invalid "
 					"in restore mode.",
 					command->name[0]);
-				if (interactive
-				    && command->cmd == IPSET_CMD_RESTORE) {
-					printf("Restore command ignored "
-					       "in interactive mode\n");
-				return 0;
-			}
+		if (interactive
+			&& command->cmd == IPSET_CMD_RESTORE) {
+			printf("Restore command ignored "
+				   "in interactive mode\n");
+			return 0;
+		}
 
-			/* Shift off matched command arg */
-			ipset_shift_argv(&argc, argv, i);
-			cmd = command->cmd;
-			switch (command->has_arg) {
-			case IPSET_MANDATORY_ARG:
-			case IPSET_MANDATORY_ARG2:
-				if (i + 1 > argc)
+		/* Shift off matched command arg */
+		ipset_shift_argv(&argc, argv, 1);
+		cmd = command->cmd;
+		switch (command->has_arg) {
+		case IPSET_MANDATORY_ARG:
+		case IPSET_MANDATORY_ARG2:
+				if (argc < 2)
 					return exit_error(PARAMETER_PROBLEM,
-						"Missing mandatory argument "
-						"to command %s",
-						command->name[0]);
+									  "Missing mandatory argument "
+									  "to command %s",
+									  command->name[0]);
 				/* Fall through */
-			case IPSET_OPTIONAL_ARG:
-				arg0 = argv[i];
-				if (i + 1 <= argc)
-					/* Shift off first arg */
-					ipset_shift_argv(&argc, argv, i);
-				break;
-			default:
-				break;
-			}
-			if (command->has_arg == IPSET_MANDATORY_ARG2) {
-				if (i + 1 > argc)
-					return exit_error(PARAMETER_PROBLEM,
-						"Missing second mandatory "
-						"argument to command %s",
-						command->name[0]);
-				arg1 = argv[i];
-				/* Shift off second arg */
-				ipset_shift_argv(&argc, argv, i);
-			}
+		case IPSET_OPTIONAL_ARG:
+			arg0 = argv[1];
+			if (argc >= 2)
+				/* Shift off first arg */
+				ipset_shift_argv(&argc, argv, 1);
+			break;
+		default:
 			break;
 		}
+		if (command->has_arg == IPSET_MANDATORY_ARG2) {
+			if (argc < 2)
+				return exit_error(PARAMETER_PROBLEM,
+								  "Missing second mandatory "
+								  "argument to command %s",
+								  command->name[0]);
+			arg1 = argv[1];
+			/* Shift off second arg */
+			ipset_shift_argv(&argc, argv, 1);
+		}
+		break;
 	}
 
 	/* Third: catch interactive mode, handle help, version */

-- 

  reply	other threads:[~2011-01-19 20:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-19 20:26 [patch 0/2] Ipset patches holger
2011-01-19 20:26 ` holger [this message]
2011-01-19 20:26 ` [patch 2/2] ipset: remove unneeded argvloop holger
2011-01-19 21:59 ` [patch 0/2] Ipset patches Jozsef Kadlecsik

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110119203559.494912348@eitzenberger.org \
    --to=holger@eitzenberger.org \
    --cc=kadlec@blackhole.kfki.hu \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).