zsh-workers
 help / color / mirror / code / Atom feed
* COMPLETE_IN_WORD dumps core if built-in functions match
@ 1995-07-29 14:22 Thorsten Meinecke
  1995-08-07 11:51 ` COMPLETE_IN_WORD dumps core if reserved word match Thorsten Meinecke
  0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Meinecke @ 1995-07-29 14:22 UTC (permalink / raw)
  To: zsh-workers

Please consider this:

  aglaia:~/wrk/zsh/zsh-2.6-beta10/Src> gdb ./zsh   
[blurb]
  (gdb) set args -f
  (gdb) r
  Starting program: /u/home/kaefer/wrk/zsh/zsh-2.6-beta10/Src/./zsh -f
  aglaia:~/wrk/zsh/zsh-2.6-beta10/Src> setopt autolist completeinword 
  aglaia:~/wrk/zsh/zsh-2.6-beta10/Src> rt
                                        ^
[cursor position is here, and completion requested]

  Program received signal SIGSEGV, Segmentation fault.
  0x804ed39 in addmatch (s=0x8059424 "epeat", t=0x8059424 "epeat")
      at zle_tricky.c:1524
  1524                *e = '\0';
  (gdb)

The obvious way around (at least for GCC) is to recompile with
-fwritable-strings.
Can anyone more proficient in zle_tricky.c hackery comment on this?
-- 
Thorsten Meinecke
<kaefer@aglaia.snafu.de>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* COMPLETE_IN_WORD dumps core if reserved word match
  1995-07-29 14:22 COMPLETE_IN_WORD dumps core if built-in functions match Thorsten Meinecke
@ 1995-08-07 11:51 ` Thorsten Meinecke
  1995-08-07 14:06   ` Zoltan Hidvegi
  1995-08-08 11:36   ` P.Stephenson
  0 siblings, 2 replies; 4+ messages in thread
From: Thorsten Meinecke @ 1995-08-07 11:51 UTC (permalink / raw)
  To: zsh-workers

I wrote, 
Subject: COMPLETE_IN_WORD dumps core if built-in functions match,

>   Starting program: /u/home/kaefer/wrk/zsh/zsh-2.6-beta10/Src/./zsh -f
>   aglaia:~/wrk/zsh/zsh-2.6-beta10/Src> setopt autolist completeinword 
>   aglaia:~/wrk/zsh/zsh-2.6-beta10/Src> rt
>                                         ^
> [cursor position is here, and completion requested]
> 
>   Program received signal SIGSEGV, Segmentation fault.
>   0x804ed39 in addmatch (s=0x8059424 "epeat", t=0x8059424 "epeat")
>       at zle_tricky.c:1524
>   1524                *e = '\0';
>   (gdb)
> 
> The obvious way around (at least for GCC) is to recompile with
> -fwritable-strings.

Digging a little further shows that only the list of 24 reserved
words is subject to this problem. We're attempting to modify
"string constants", which can't be done portably.

The fix is to copy these words, at the expense of a-hundred-and-a-
few bytes increased memory usage, as it was done in earlier releases.

This is still for zsh-2.6-beta10:


*** hashtable.c.orig	Sat Jul  1 00:06:17 1995
--- hashtable.c	Mon Aug  7 01:49:09 1995
***************
*** 441,454 ****
      reswdtab->printinfo = printhashtabinfo;
      reswdtab->tablename = ztrdup("reswdtab");
  #endif
  
!     /* Add the actual words, not copies, to the table, *
!      * as we do not expect to modify the table again.  */
      for (i = 0; reswds[i]; i++) {
  	struct reswd *ptr = (struct reswd *) zcalloc(sizeof *ptr);
  	ptr->cmd = i + DO;
! 	reswdtab->addnode(reswdtab, reswds[i], ptr);
      }
  }
  
  
--- 441,455 ----
      reswdtab->printinfo = printhashtabinfo;
      reswdtab->tablename = ztrdup("reswdtab");
  #endif
  
!     /* Add copies of the actual words to the table, as we do not *
!      * expect to modify the table permanently, but we do insert  *
!      * end-of-string markers for COMPLETE_IN_WORD temporarily    */
      for (i = 0; reswds[i]; i++) {
  	struct reswd *ptr = (struct reswd *) zcalloc(sizeof *ptr);
  	ptr->cmd = i + DO;
! 	reswdtab->addnode(reswdtab, ztrdup(reswds[i]), ptr);
      }
  }
  
  


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: COMPLETE_IN_WORD dumps core if reserved word match
  1995-08-07 11:51 ` COMPLETE_IN_WORD dumps core if reserved word match Thorsten Meinecke
@ 1995-08-07 14:06   ` Zoltan Hidvegi
  1995-08-08 11:36   ` P.Stephenson
  1 sibling, 0 replies; 4+ messages in thread
From: Zoltan Hidvegi @ 1995-08-07 14:06 UTC (permalink / raw)
  To: zsh-workers

Thorsten Meinecke wrote:
> I wrote, 
> Subject: COMPLETE_IN_WORD dumps core if built-in functions match,
> 
> >   Starting program: /u/home/kaefer/wrk/zsh/zsh-2.6-beta10/Src/./zsh -f
> >   aglaia:~/wrk/zsh/zsh-2.6-beta10/Src> setopt autolist completeinword 
> >   aglaia:~/wrk/zsh/zsh-2.6-beta10/Src> rt
> >                                         ^
> > [cursor position is here, and completion requested]
> > 
> >   Program received signal SIGSEGV, Segmentation fault.
> >   0x804ed39 in addmatch (s=0x8059424 "epeat", t=0x8059424 "epeat")
> >       at zle_tricky.c:1524
> >   1524                *e = '\0';
> >   (gdb)
> > 
> > The obvious way around (at least for GCC) is to recompile with
> > -fwritable-strings.
> 
> Digging a little further shows that only the list of 24 reserved
> words is subject to this problem. We're attempting to modify
> "string constants", which can't be done portably.
> 
> The fix is to copy these words, at the expense of a-hundred-and-a-
> few bytes increased memory usage, as it was done in earlier releases.

I think it would be better to modify the code which uses the end-of-string
marks. I do not like new ztrdups. Also it requires some additional CPU time as
well (malloc can be quite slow, especially with zsh-mem, which queues signals
befor each malloc). The proper solution shouldn't be too difficult, be I have
some other things to do now.

Zoltan


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: COMPLETE_IN_WORD dumps core if reserved word match
  1995-08-07 11:51 ` COMPLETE_IN_WORD dumps core if reserved word match Thorsten Meinecke
  1995-08-07 14:06   ` Zoltan Hidvegi
@ 1995-08-08 11:36   ` P.Stephenson
  1 sibling, 0 replies; 4+ messages in thread
From: P.Stephenson @ 1995-08-08 11:36 UTC (permalink / raw)
  To: Zsh hackers list

kaefer@aglaia.snafu.de wrote:
> I wrote, 
> Subject: COMPLETE_IN_WORD dumps core if built-in functions match,
>
> > The obvious way around (at least for GCC) is to recompile with
> > -fwritable-strings.
> 
> The fix is to copy these words, at the expense of a-hundred-and-a-
> few bytes increased memory usage, as it was done in earlier releases.

Yuk.  Having to copy permanent values is not much more `politically
correct' than using -fwritable-strings.  Why can't we just call
dupstring() before sticking in the null byte?  I don't see why `s'
should have to point to the original string rather than a copy.

There was a line like this
    t = s += (ispattern ? 0 : pl);
    e += t - s;
but surely the second line is redundant?  Anyway, I deleted it.

*** Src/zle_tricky.c.sav	Fri Jul 28 12:47:31 1995
--- Src/zle_tricky.c	Tue Aug  8 12:29:37 1995
***************
*** 1395,1401 ****
  addmatch(char *s, char *t)
  {
      int test = 0, sl = strlen(s), pl = rpl, cc = 0, *bp, *ep;
!     char sav = 0, *e = NULL, *tt, *te, *fc, **fm;
      Comp cp = patcomp;
      Param pm;
      LinkList l = matches;
--- 1395,1401 ----
  addmatch(char *s, char *t)
  {
      int test = 0, sl = strlen(s), pl = rpl, cc = 0, *bp, *ep;
!     char *e = NULL, *tt, *te, *fc, **fm;
      Comp cp = patcomp;
      Param pm;
      LinkList l = matches;
***************
*** 1513,1528 ****
      if (!test)
  	return;
  
!     t = s += (ispattern ? 0 : pl);
!     e += t - s;
!     s = t;
! 
!     if (ispattern)
! 	e = NULL, sav = '\0';
!     else {
! 	if ((sav = *e)) {
! 	    *e = '\0';
! 	    t = dupstring(t);
  	}
      }
  
--- 1513,1526 ----
      if (!test)
  	return;
  
!     if (ispattern) {
! 	t = s;
!     } else {
! 	t = s += pl;
! 	if (*e) {
! 	    sl = e - s;
! 	    t = s = dupstring(t);
! 	    s[sl] = '\0';
  	}
      }
  
***************
*** 1561,1568 ****
  	    fshortl = sl, fshortest = t;
  	else
  	    shortl = sl, shortest = t;
-     if (sav)
- 	*e = sav;
  }
  
  #ifdef HAVE_NIS
--- 1559,1564 ----

-- 
Peter Stephenson <P.Stephenson@swansea.ac.uk>  Tel: +44 1792 205678 extn. 4461
WWW:  http://python.swan.ac.uk/~pypeters/      Fax: +44 1792 295324
Department of Physics, University of Wales, Swansea,
Singleton Park, Swansea, SA2 8PP, U.K.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1995-08-08 12:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-07-29 14:22 COMPLETE_IN_WORD dumps core if built-in functions match Thorsten Meinecke
1995-08-07 11:51 ` COMPLETE_IN_WORD dumps core if reserved word match Thorsten Meinecke
1995-08-07 14:06   ` Zoltan Hidvegi
1995-08-08 11:36   ` P.Stephenson

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).