threads / patch / 11147

patchgit config: Don't rely on regexec() returning 1 on non-match

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

## tl;dr

3 messages between Dec 5, 2007 and Dec 5, 2007. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

Björn Steinbrink· Dec 5, 2007, 15:11 UTC · lore

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(-)
Show changes to builtin-config.c +3 −3
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· Dec 5, 2007, 15:14 UTC · re: Björn Steinbrink · lore

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

Hi,
On Wed, 5 Dec 2007, Björn Steinbrink wrote:
Show 10 quoted lines
> 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

← back to recent threads