# [PATCH] git config: Don't rely on regexec() returning 1 on non-match

3 messages from 2007-12-05 to 2007-12-05. Participants: Björn Steinbrink, Johannes Schindelin, Junio C Hamano.
Thread: https://gitlist.dev/t/11147

## Björn Steinbrink, 2007-12-05 15:11

Subject: [PATCH] git config: Don't rely on regexec() returning 1 on non-match
Message-ID: <1196867484-22188-1-git-send-email-B.Steinbrink@gmx.de>
URL: https://gitlist.dev/e/1196867484-22188-1-git-send-email-B.Steinbrink%40gmx.de

```
Some systems don't return 1 from regexec() when the pattern does not
match (notably HP-UX which returns 20). Fortunately, there's the
REG_NOMATCH constant, which we can use as the expected return value
and test for that instead of "1 XOR retval".

Bug identified by Dscho and H.Merijn Brand.

Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>
Tested-by: H.Merijn Brand <h.m.brand@xs4all.nl>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>
---
 builtin-config.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/builtin-config.c b/builtin-config.c
index 4c9ded3..9fda4e4 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -11,7 +11,7 @@ static regex_t *regexp;
 static int show_keys;
 static int use_key_regexp;
 static int do_all;
-static int do_not_match;
+static int expected_regexec_result;
 static int seen;
 static char delim = '=';
 static char key_delim = ' ';
@@ -38,7 +38,7 @@ static int show_config(const char* key_, const char* value_)
 	if (use_key_regexp && regexec(key_regexp, key_, 0, NULL, 0))
 		return 0;
 	if (regexp != NULL &&
-			 (do_not_match ^
+			 (expected_regexec_result !=
 			  regexec(regexp, (value_?value_:""), 0, NULL, 0)))
 		return 0;
 
@@ -101,7 +101,7 @@ static int get_value(const char* key_, const char* regex_)
 
 	if (regex_) {
 		if (regex_[0] == '!') {
-			do_not_match = 1;
+			expected_regexec_result = REG_NOMATCH;
 			regex_++;
 		}
 
-- 
1.5.3.GIT

```

## Johannes Schindelin, 2007-12-05 15:14

Subject: Re: [PATCH] git config: Don't rely on regexec() returning 1 on non-match
Message-ID: <Pine.LNX.4.64.0712051513570.27959@racer.site>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0712051513570.27959%40racer.site
In-Reply-To: <1196867484-22188-1-git-send-email-B.Steinbrink@gmx.de>

```
Hi,

On Wed, 5 Dec 2007, Björn Steinbrink wrote:

> Some systems don't return 1 from regexec() when the pattern does not
> match (notably HP-UX which returns 20). Fortunately, there's the
> REG_NOMATCH constant, which we can use as the expected return value
> and test for that instead of "1 XOR retval".
> 
> Bug identified by Dscho and H.Merijn Brand.
> 
> Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>
> Tested-by: H.Merijn Brand <h.m.brand@xs4all.nl>
> Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>

ACK

Ciao,
Dscho

```

## Junio C Hamano, 2007-12-05 19:34

Subject: Re: [PATCH] git config: Don't rely on regexec() returning 1 on non-match
Message-ID: <7vy7c9orzj.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vy7c9orzj.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <Pine.LNX.4.64.0712051513570.27959@racer.site>

```
Thanks.  I'll apply but http://git.pastebin.com/m24a4e277 feels somewhat
safer and less intrusive.

```
