From: Tanaka Akira <akr@jaist.ac.jp>
To: zsh-workers@sunsite.auc.dk
Subject: PATCH: zregexparse dumps core when match data is not defined
Date: 03 Feb 2000 20:58:48 +0900 [thread overview]
Message-ID: <rsqr9euo5tz.fsf@crane.jaist.ac.jp> (raw)
I forgot to handle the situation which match data is not defined.
% zsh -f
serein% zmodload zsh/zutil
serein% zregexparse p1 p2 a /a/
zsh: segmentation fault (core dumped) zsh -f
Index: Src/Modules/zutil.c
===================================================================
RCS file: /projects/zsh/zsh/Src/Modules/zutil.c,v
retrieving revision 1.1.1.10
diff -u -r1.1.1.10 zutil.c
--- Src/Modules/zutil.c 2000/02/03 09:40:04 1.1.1.10
+++ Src/Modules/zutil.c 2000/02/03 11:57:20
@@ -683,6 +683,55 @@
/* Zregexparse stuff. */
typedef struct {
+ char **match;
+ char **mbegin;
+ char **mend;
+} MatchData;
+
+static void
+savematch(MatchData *m)
+{
+ char **a;
+
+ PERMALLOC {
+ a = getaparam("match");
+ m->match = a ? arrdup(a) : NULL;
+ a = getaparam("mbegin");
+ m->mbegin = a ? arrdup(a) : NULL;
+ a = getaparam("mend");
+ m->mend = a ? arrdup(a) : NULL;
+ } LASTALLOC;
+}
+
+static void
+restorematch(MatchData *m)
+{
+ if (m->match)
+ setaparam("match", m->match);
+ else
+ unsetparam("match");
+ if (m->mbegin)
+ setaparam("mbegin", m->mbegin);
+ else
+ unsetparam("mbegin");
+ if (m->mend)
+ setaparam("mend", m->mend);
+ else
+ unsetparam("mend");
+}
+
+static void
+freematch(MatchData *m)
+{
+ if (m->match)
+ freearray(m->match);
+ if (m->mbegin)
+ freearray(m->mbegin);
+ if (m->mend)
+ freearray(m->mend);
+}
+
+typedef struct {
int cutoff;
char *pattern;
Patprog patprog;
@@ -692,8 +741,8 @@
} RParseState;
typedef struct {
- RParseState *state;
- LinkList actions;
+ RParseState *state;
+ LinkList actions;
} RParseBranch;
typedef struct {
@@ -982,14 +1031,9 @@
nexts = sm->in;
addlinknode(nextslist, nexts);
do {
- char **savematch1, **savembegin1, **savemend1;
- char **savematch2, **savembegin2, **savemend2;
+ MatchData match1, match2;
- PERMALLOC {
- savematch1 = arrdup(getaparam("match"));
- savembegin1 = arrdup(getaparam("mbegin"));
- savemend1 = arrdup(getaparam("mend"));
- } LASTALLOC;
+ savematch(&match1);
for (ln = firstnode(nexts); ln; ln = nextnode(ln)) {
int i;
@@ -1012,18 +1056,8 @@
if (*subj++ == Meta)
subj++;
- PERMALLOC {
- savematch2 = arrdup(getaparam("match"));
- savembegin2 = arrdup(getaparam("mbegin"));
- savemend2 = arrdup(getaparam("mend"));
- } LASTALLOC;
-
- if (savematch1)
- setaparam("match", savematch1);
- if (savembegin1)
- setaparam("mbegin", savembegin1);
- if (savemend1)
- setaparam("mend", savemend1);
+ savematch(&match2);
+ restorematch(&match1);
for (aln = firstnode(br->actions); aln; aln = nextnode(aln)) {
char *action = getdata(aln);
@@ -1031,12 +1065,7 @@
if (action)
execstring(action, 1, 0);
}
- if (savematch2)
- setaparam("match", savematch2);
- if (savembegin2)
- setaparam("mbegin", savembegin2);
- if (savemend2)
- setaparam("mend", savemend2);
+ restorematch(&match2);
point2 += len;
setiparam(var2, point2);
@@ -1050,15 +1079,9 @@
addlinknode(nextslist, nexts);
break;
}
- }
- if (!ln) {
- if (savematch1)
- freearray(savematch1);
- if (savembegin1)
- freearray(savembegin1);
- if (savemend1)
- freearray(savemend1);
}
+ if (!ln)
+ freematch(&match1);
} while (ln);
if (!comp && !*subj)
--
Tanaka Akira
reply other threads:[~2000-02-03 11:59 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=rsqr9euo5tz.fsf@crane.jaist.ac.jp \
--to=akr@jaist.ac.jp \
--cc=zsh-workers@sunsite.auc.dk \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).