Skip to content

Commit 3275863

Browse files
committed
clar: verify command line arguments before execute
When executing `libgit2_clar -smerge -invalid_option`, it will first execute the merge test suite and afterwards output help because of the invalid option. With this changa, it verifies all options before execute. If there are any invalid options, it will output help and exit without actually executing the test suites.
1 parent 46e1dab commit 3275863

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tests/clar.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,11 +313,18 @@ clar_parse_args(int argc, char **argv)
313313
{
314314
int i;
315315

316+
/* Verify options before execute */
316317
for (i = 1; i < argc; ++i) {
317318
char *argument = argv[i];
318319

319-
if (argument[0] != '-')
320+
if (argument[0] != '-' || argument[1] == '\0'
321+
|| strchr("sixvqQl", argument[1]) == NULL) {
320322
clar_usage(argv[0]);
323+
}
324+
}
325+
326+
for (i = 1; i < argc; ++i) {
327+
char *argument = argv[i];
321328

322329
switch (argument[1]) {
323330
case 's':
@@ -391,7 +398,7 @@ clar_parse_args(int argc, char **argv)
391398
break;
392399

393400
default:
394-
clar_usage(argv[0]);
401+
assert(!"Unexpected commandline argument!");
395402
}
396403
}
397404
}

0 commit comments

Comments
 (0)