Git Mailing List Archive on lore.kernel.org
 help / color / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Carlo Marcelo Arenas Belón" <carenas@gmail.com>
Cc: git@vger.kernel.org, emaste@freebsd.org, sunshine@sunshineco.com
Subject: Re: [PATCH v2] t4210: detect REG_ILLSEQ dynamically
Date: Fri, 15 May 2020 14:48:23 -0700
Message-ID: <xmqqblmolviw.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <xmqqmu69kktq.fsf@gitster.c.googlers.com> (Junio C. Hamano's message of "Fri, 15 May 2020 13:24:49 -0700")

Junio C Hamano <gitster@pobox.com> 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>]");
 }

  reply index

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-13 11:16 [PATCH] " Carlo Marcelo Arenas Belón
2020-05-13 15:44 ` Eric Sunshine
2020-05-13 16:20   ` Junio C Hamano
2020-05-13 20:18   ` Carlo Marcelo Arenas Belón
2020-05-13 20:37     ` Junio C Hamano
2020-05-13 21:04       ` Carlo Marcelo Arenas Belón
2020-05-13 18:02 ` [RFC PATCH v2] " Carlo Marcelo Arenas Belón
2020-05-13 20:40   ` Eric Sunshine
2020-05-15 18:00   ` Junio C Hamano
2020-05-15 18:18     ` Carlo Marcelo Arenas Belón
2020-05-15 19:51 ` [PATCH " Carlo Marcelo Arenas Belón
2020-05-15 20:24   ` Junio C Hamano
2020-05-15 21:48     ` Junio C Hamano [this message]
2020-05-18 18:44   ` [PATCH v3 0/2] auto detect REG_ILLSEQ Carlo Marcelo Arenas Belón
2020-05-18 18:44     ` [PATCH v3 1/2] t/helper: teach test-regex to report pattern errors (like REG_ILLSEQ) Carlo Marcelo Arenas Belón
2020-05-18 20:15       ` Junio C Hamano
2020-05-18 18:44     ` [PATCH v3 2/2] t4210: detect REG_ILLSEQ dynamically and skip affected tests Carlo Marcelo Arenas Belón

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=xmqqblmolviw.fsf@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=carenas@gmail.com \
    --cc=emaste@freebsd.org \
    --cc=git@vger.kernel.org \
    --cc=sunshine@sunshineco.com \
    /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

Git Mailing List Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/git/0 git/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 git git/ https://lore.kernel.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.git


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git