From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29504 invoked from network); 28 Aug 2001 08:36:41 -0000 Received: from sunsite.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 28 Aug 2001 08:36:41 -0000 Received: (qmail 17246 invoked by alias); 28 Aug 2001 08:36:33 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 15717 Received: (qmail 17234 invoked from network); 28 Aug 2001 08:36:32 -0000 From: Sven Wischnowsky Message-ID: <15243.22511.888850.924717@gargle.gargle.HOWL> Date: Tue, 28 Aug 2001 10:35:59 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: zsh-workers@sunsite.dk Subject: PATCH: Re: Seg Fault in paramsubst() In-Reply-To: <20010828062406.54685.qmail@web10405.mail.yahoo.com> References: <1010824170526.ZM28196@candle.brasslantern.com> <20010828062406.54685.qmail@web10405.mail.yahoo.com> X-Mailer: VM 6.92 under 21.1 (patch 3) "Acadia" XEmacs Lucid Felix Rosencrantz wrote: > When using this in my completer I would sometimes get seg faults. Below > is a stack trace from gdb. I think this stack trace would only occur if there > were either no matches or just one. Though it might just happen in one of > those situations. bufferwords() might return a NULL pointer, so we should check if it did. Everywhere. Bye Sven Index: Src/subst.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/subst.c,v retrieving revision 1.21 diff -u -r1.21 subst.c --- Src/subst.c 2001/08/07 10:18:32 1.21 +++ Src/subst.c 2001/08/28 08:32:38 @@ -1833,7 +1833,7 @@ } else list = bufferwords(NULL, val, NULL); - if (!firstnode(list)) + if (!list || !firstnode(list)) val = dupstring(""); else if (!nextnode(firstnode(list))) val = getdata(firstnode(list)); Index: Src/Modules/parameter.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Modules/parameter.c,v retrieving revision 1.21 diff -u -r1.21 parameter.c --- Src/Modules/parameter.c 2001/07/09 16:05:14 1.21 +++ Src/Modules/parameter.c 2001/08/28 08:32:38 @@ -1105,9 +1105,9 @@ int i = addhistnum(curhist, -1, HIST_FOREIGN), iw; Histent he = gethistent(i, GETHIST_UPWARD); - ll = bufferwords(NULL, NULL, NULL); - for (n = firstnode(ll); n; incnode(n)) - pushnode(l, getdata(n)); + if ((ll = bufferwords(NULL, NULL, NULL))) + for (n = firstnode(ll); n; incnode(n)) + pushnode(l, getdata(n)); while (he) { for (iw = he->nwords - 1; iw >= 0; iw--) { Index: Src/Zle/zle_misc.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_misc.c,v retrieving revision 1.4 diff -u -r1.4 zle_misc.c --- Src/Zle/zle_misc.c 2000/05/10 15:01:19 1.4 +++ Src/Zle/zle_misc.c 2001/08/28 08:32:39 @@ -549,13 +549,13 @@ int i; char *p = NULL; - l = bufferwords(NULL, NULL, &i); + if ((l = bufferwords(NULL, NULL, &i))) + for (n = firstnode(l); n; incnode(n)) + if (!i--) { + p = getdata(n); + break; + } - for (n = firstnode(l); n; incnode(n)) - if (!i--) { - p = getdata(n); - break; - } if (p) { int len = strlen(p); -- Sven Wischnowsky wischnow@informatik.hu-berlin.de