{"thread":{"id":"11147","subject":"[PATCH] git config: Don't rely on regexec() returning 1 on non-match","startedAt":"2007-12-05T15:11:24Z","lastAt":"2007-12-05T19:34:40Z","messageCount":3,"participants":["Björn Steinbrink","Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"62017","messageId":"1196867484-22188-1-git-send-email-B.Steinbrink@gmx.de","threadId":"11147","inReplyTo":null,"subject":"[PATCH] git config: Don't rely on regexec() returning 1 on non-match","fromName":"Björn Steinbrink","fromEmail":"b.steinbrink@gmx.de","sentAt":"2007-12-05T15:11:24Z","receivedAt":"2007-12-05T15:11:24Z","isPatch":true,"sender":{"key":"b.steinbrink@gmx.de","avatar":"https://avatars.githubusercontent.com/u/230962?v=4"},"body":"Some systems don't return 1 from regexec() when the pattern does not\nmatch (notably HP-UX which returns 20). Fortunately, there's the\nREG_NOMATCH constant, which we can use as the expected return value\nand test for that instead of \"1 XOR retval\".\n\nBug identified by Dscho and H.Merijn Brand.\n\nSigned-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>\nTested-by: H.Merijn Brand <h.m.brand@xs4all.nl>\nCc: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n---\n builtin-config.c |    6 +++---\n 1 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin-config.c b/builtin-config.c\nindex 4c9ded3..9fda4e4 100644\n--- a/builtin-config.c\n+++ b/builtin-config.c\n@@ -11,7 +11,7 @@ static regex_t *regexp;\n static int show_keys;\n static int use_key_regexp;\n static int do_all;\n-static int do_not_match;\n+static int expected_regexec_result;\n static int seen;\n static char delim = '=';\n static char key_delim = ' ';\n@@ -38,7 +38,7 @@ static int show_config(const char* key_, const char* value_)\n \tif (use_key_regexp && regexec(key_regexp, key_, 0, NULL, 0))\n \t\treturn 0;\n \tif (regexp != NULL &&\n-\t\t\t (do_not_match ^\n+\t\t\t (expected_regexec_result !=\n \t\t\t  regexec(regexp, (value_?value_:\"\"), 0, NULL, 0)))\n \t\treturn 0;\n \n@@ -101,7 +101,7 @@ static int get_value(const char* key_, const char* regex_)\n \n \tif (regex_) {\n \t\tif (regex_[0] == '!') {\n-\t\t\tdo_not_match = 1;\n+\t\t\texpected_regexec_result = REG_NOMATCH;\n \t\t\tregex_++;\n \t\t}\n \n-- \n1.5.3.GIT\n"},{"id":"62018","messageId":"Pine.LNX.4.64.0712051513570.27959@racer.site","threadId":"11147","inReplyTo":"1196867484-22188-1-git-send-email-B.Steinbrink@gmx.de","subject":"Re: [PATCH] git config: Don't rely on regexec() returning 1 on non-match","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-12-05T15:14:11Z","receivedAt":"2007-12-05T15:14:11Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Wed, 5 Dec 2007, Björn Steinbrink wrote:\n\n> Some systems don't return 1 from regexec() when the pattern does not\n> match (notably HP-UX which returns 20). Fortunately, there's the\n> REG_NOMATCH constant, which we can use as the expected return value\n> and test for that instead of \"1 XOR retval\".\n> \n> Bug identified by Dscho and H.Merijn Brand.\n> \n> Signed-off-by: Björn Steinbrink <B.Steinbrink@gmx.de>\n> Tested-by: H.Merijn Brand <h.m.brand@xs4all.nl>\n> Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\nACK\n\nCiao,\nDscho\n"},{"id":"62045","messageId":"7vy7c9orzj.fsf@gitster.siamese.dyndns.org","threadId":"11147","inReplyTo":"Pine.LNX.4.64.0712051513570.27959@racer.site","subject":"Re: [PATCH] git config: Don't rely on regexec() returning 1 on non-match","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-05T19:34:40Z","receivedAt":"2007-12-05T19:34:40Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks.  I'll apply but http://git.pastebin.com/m24a4e277 feels somewhat\nsafer and less intrusive.\n"}]}