about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>2000-01-21 10:07:35 +0000
committerTanaka Akira <akr@users.sourceforge.net>2000-01-21 10:07:35 +0000
commit09a9a37aaccf043ad6e9c66344a1b722df633013 (patch)
treee3d417fc6d1ded0f78e5f3c3a020f09bc212470c /Src
parent8750814108c3b613c5e778e03102020a35723f71 (diff)
downloadzsh-09a9a37aaccf043ad6e9c66344a1b722df633013.tar.gz
zsh-09a9a37aaccf043ad6e9c66344a1b722df633013.tar.xz
zsh-09a9a37aaccf043ad6e9c66344a1b722df633013.zip
zsh-workers/9395
Diffstat (limited to 'Src')
-rw-r--r--Src/exec.c38
-rw-r--r--Src/parse.c3
-rw-r--r--Src/text.c1
3 files changed, 30 insertions, 12 deletions
diff --git a/Src/exec.c b/Src/exec.c
index ae13ba016..6310d5431 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -3281,7 +3281,6 @@ stripkshdef(Eprog prog, char *name)
 {
     Wordcode pc = prog->prog;
     wordcode code;
-    Eprog ret;
 
     if (!prog)
 	return NULL;
@@ -3301,16 +3300,33 @@ stripkshdef(Eprog prog, char *name)
 	*pc != 1 || strcmp(name, ecrawstr(prog, pc + 1)))
 	return prog;
 
-    ret = (Eprog) zhalloc(sizeof(*prog));
-    ret->len = (WC_FUNCDEF_SKIP(code) - 3) * sizeof(wordcode);
-    ret->prog = pc + 3;
-    ret->strs = (char *) (pc + pc[3]);
-    ret->shf = NULL;
-    ret->pats = prog->pats;
-    ret->npats = prog->npats;
-    ret->heap = 1;
-
-    return ret;
+    {
+	Eprog ret;
+	Wordcode end = pc + WC_FUNCDEF_SKIP(code);
+	int nprg = pc[2] - 4;
+	int npats = pc[3];
+	int plen, len, i;
+	Patprog *pp;
+
+	pc += 4;
+
+	plen = (end - pc) * sizeof(wordcode);
+	len = plen + (npats * sizeof(Patprog));
+
+	ret = (Eprog) zhalloc(sizeof(*ret));
+	ret->heap = 1;
+	ret->len = len;
+	ret->npats = npats;
+	ret->pats = pp = (Patprog *) zhalloc(len);
+	ret->prog = (Wordcode) (ret->pats + npats);
+	for (i = npats; i--; pp++)
+	    *pp = dummy_patprog1;
+	memcpy(ret->prog, pc, plen);
+	ret->strs = (char *) (ret->prog + nprg);
+	ret->shf = NULL;
+
+	return ret;
+    }
 }
 
 /* check to see if AUTOCD applies here */
diff --git a/Src/parse.c b/Src/parse.c
index 1e1f9b02f..95a752799 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -2467,10 +2467,11 @@ ecgetarr(Estate s, int num, int dup)
 {
     char **ret, **rp;
 
-    ret = rp = (char **) zhalloc(num * sizeof(char *));
+    ret = rp = (char **) zhalloc((num + 1) * sizeof(char *));
 
     while (num--)
 	*rp++ = ecgetstr(s, dup);
+    *rp = NULL;
 
     return ret;
 }
diff --git a/Src/text.c b/Src/text.c
index b75ea193a..fc5a2a5c7 100644
--- a/Src/text.c
+++ b/Src/text.c
@@ -636,6 +636,7 @@ gettext2(Estate state)
 			break;
 		    case COND_MOD:
 			taddstr(ecgetstr(state, 0));
+			taddchr(' ');
 			taddlist(state, WC_COND_SKIP(code));
 			stack = 1;
 			break;