Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: zsh/regex and =~
- X-seq: zsh-workers 23342
- From: Phil Pennock <zsh-workers+phil.pennock@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: Re: PATCH: zsh/regex and =~
- Date: Sat, 28 Apr 2007 17:51:28 -0700
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=first1; d=spodhuis.org; h=Received:Date:From:To:Subject:Message-ID:Mail-Followup-To:References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; b=fJDBIzd+h6hjENX4Phhw15AU394X8tl3t0qglEbqJ9WHGDDvZeWH6fPw0qhgIs2jbigkpiQCi3zqfz8h1kbusQdTHxnfvYMEM+mqgdjY0revpouENevNK3hdlCXbxYasyuoYiHhywf1ScSGUyB6L+ipRePNsjIOIPAUopbMZQn4=;
- In-reply-to: <20070428075635.GA17419@xxxxxxxxxxxxxxxxxxxx>
- Mail-followup-to: zsh-workers@xxxxxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20070428075635.GA17419@xxxxxxxxxxxxxxxxxxxx>
On 2007-04-28 at 00:56 -0700, Phil Pennock wrote:
> The attached patch and files, which includes documentation, adds a new
> loadable module, zsh/regex. I've not examined widechar issues and which
> regex libraries actually do handle these. I've not looked at linkage
> issues on platforms where regex (the POSIX interface, not regexp) is not
> a part of libc.
I noticed a gcc complaint that a variable might be used uninitialised;
this was bogus, but understandable. The first patch below fixes it.
The second patch is a spelling correction in the docs. Alternatively,
it might be a sign that the option needs to be renamed ...
arr is only initialised if nelem. Later there are two references to it.
The second is guarded by "if (nelem)"; the first is guarded by
"if (isset(BASHREMATCH))". If BASHREMATCH is set, nelem is always at
least 1. Assuming re.re_nsub is never negative, which it isn't. And
the patch also affirms this for sheer paranoia's sake.
-Phil
--- Src/Modules/regex.c.old Sat Apr 28 17:40:12 2007
+++ Src/Modules/regex.c Sat Apr 28 17:43:27 2007
@@ -75,6 +75,11 @@ zcond_regex_match(char **a, int id)
/* re.re_nsub is number of parenthesized groups, we also need
* 1 for the 0 offset, which is the entire matched portion
*/
+ if (re.re_nsub < 0) {
+ zwarn("INTERNAL ERROR: regcomp() returned "
+ "negative subpattern count %d", re.re_nsub);
+ break;
+ }
matchessz = (re.re_nsub + 1) * sizeof(regmatch_t);
matches = zalloc(matchessz);
r = regexec(&re, lhstr, re.re_nsub+1, matches, reflags);
@@ -88,6 +93,7 @@ zcond_regex_match(char **a, int id)
start = 1;
nelem = re.re_nsub;
}
+ arr = NULL; /* bogus gcc warning of used uninitialised */
/* entire matched portion + re_nsub substrings + NULL */
if (nelem) {
arr = x = (char **) zalloc(sizeof(char *) * (nelem + 1));
--- Doc/Zsh/mod_regex.yo.old Sat Apr 28 17:45:57 2007
+++ Doc/Zsh/mod_regex.yo Sat Apr 28 17:45:35 2007
@@ -15,7 +15,7 @@
[[ alphabetical -regex-match ^a([^a]+)a([^a]+)a ]] && print -l $MATCH X $match
-If tt(REGMATCH_PCRE) is not set, then the tt(=~) operator will automatically
+If tt(REMATCH_PCRE) is not set, then the tt(=~) operator will automatically
load this module as needed and will invoke the tt(-regex-match) operator.
If tt(BASH_REMATCH) is set, then tt($BASH_REMATCH) will be set instead of
Messages sorted by:
Reverse Date,
Date,
Thread,
Author