Junio C Hamano <gitster@xxxxxxxxx> writes: >> else if (argc < 3) >> usage("test-tool regex --bug\n" >> - "test-tool regex <pattern> <string> [<options>]"); >> + "test-tool regex [--silent] <pattern> <string> [<options>]"); >> >> + if (!strcmp(argv[1], "--silent")) { >> + silent = 1; >> + argv++; >> + } > > This looks fishy---if argc==3 and the first one is "--silent", only > the <pattern> is left in argv and before taking <string> out of the > argv, we need to ensure argc is still large enough, but I do not > think that is done below: > ... > Not that it matters _too_ much as this is merely a test helper and > it would not hurt anybody as long as our callers are careful. But it still bothers me. Perhaps like this? If I were writing this from scratch, I would probably increment argv++ once as early as possible and consistently access argv[0] or *argv++, but that would make the patch even noisier. t/helper/test-regex.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/t/helper/test-regex.c b/t/helper/test-regex.c index 7a8ddce45b..e68b4f6a73 100644 --- a/t/helper/test-regex.c +++ b/t/helper/test-regex.c @@ -46,16 +46,23 @@ int cmd__regex(int argc, const char **argv) regmatch_t m[1]; char errbuf[64]; - if (argc == 2 && !strcmp(argv[1], "--bug")) - return test_regex_bug(); - else if (argc < 3) - usage("test-tool regex --bug\n" - "test-tool regex [--silent] <pattern> <string> [<options>]"); + if (argc < 2) + goto usage; + if (!strcmp(argv[1], "--bug")) { + if (argc == 2) + return test_regex_bug(); + else + goto usage; + } if (!strcmp(argv[1], "--silent")) { - silent = 1; + silent = 0; argv++; + argc--; } + if (argc < 3) + goto usage; + argv++; pat = *argv++; str = *argv++; @@ -84,4 +91,8 @@ int cmd__regex(int argc, const char **argv) return 1; return 0; + +usage: + usage("test-tool regex --bug\n" + "test-tool regex [--silent] <pattern> <string> [<options>]"); }