[PATCH 2/2] sparse/semind: robustify parse_cmdline_add()

Oleg Nesterov <[email protected]> Fri, 26 Dec 2025 15:32:24 +0100
Newsgroups org.kernel.vger.linux-sparse
Message-ID <[email protected]>
"semind add -ftabstop=8 ..." works as expected, but (for example)
"semind add --param=dissect-show-all-symbols ..." doesn't, this
arg is not passed to sparse_initialize().

Because in the latter case getopt_long() increments optind when it
sees --param=dissect-show-all-symbols. I have no idea if getopt_long()
is correct or not, but lets change parse_cmdline_add() so that it doesn't
depend on getopt_long()'s behaviour.

Signed-off-by: Oleg Nesterov <[email protected]>
---
 semind.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/semind.c b/semind.c
index fa084e04..e9708444 100644
--- a/semind.c
+++ b/semind.c
@@ -298,7 +298,7 @@ static void parse_cmdline_add(int argc, char **argv)
 		{ "help", no_argument, NULL, 'h' },
 		{ NULL }
 	};
-	int c;
+	int parsed = optind, c;
 
 	opterr = 0;
 
@@ -315,6 +315,7 @@ static void parse_cmdline_add(int argc, char **argv)
 			case '?':
 				goto done;
 		}
+		parsed = optind;
 	}
 done:
 	if (optind == argc) {
@@ -327,9 +328,8 @@ done:
 	dissect_show_all_symbols = 1;
 
 	// step back since sparse_initialize will ignore argv[0].
-	optind--;
-
-	sparse_initialize(argc - optind, argv + optind, &semind_filelist);
+	parsed--;
+	sparse_initialize(argc - parsed, argv + parsed, &semind_filelist);
 }
 
 static void parse_cmdline_rm(int argc, char **argv)
-- 
2.52.0