zsh-workers
 help / color / mirror / code / Atom feed
From: Zoltan Hidvegi <hzoli@cs.elte.hu>
To: pws@ifh.de (Peter Stephenson)
Cc: zsh-workers@math.gatech.edu
Subject: Re: readonly bug
Date: Tue, 7 Jan 1997 18:09:25 +0100 (MET)	[thread overview]
Message-ID: <199701071709.SAA24255@bolyai.cs.elte.hu> (raw)
In-Reply-To: <199701071356.OAA09615@sgi.ifh.de> from Peter Stephenson at "Jan 7, 97 02:56:40 pm"

Peter Stephenson wrote:
> haven't time to check this out further just now:
> (there was some IFS stuff around to make this useful but it turns out that's
> not necessary)
> 
> % readonly vers=foo
> % vers=(${=ZSH_VERSION})
> Segmentation fault (core dumped)

Unfortunately read-only variables are not handled very well in most places.
Here is a fix.  After that zsh prints error message when you attempt to
change a read-only variable.  Patch applies to both zsh-3.0.2 and zsh-3.1.0

It makes createparam() fail and return NULL when you attempt to crearte an
existing non-local parameter.

Zoltan


*** Src/builtin.c	1997/01/05 23:33:32	3.1.1.10
--- Src/builtin.c	1997/01/07 16:27:56
***************
*** 1842,1847 ****
--- 1842,1851 ----
  	    }
  	} else {
  	    if (bit) {
+ 		if (pm->flags & PM_READONLY) {
+ 		    on |= ~off & PM_READONLY;
+ 		    pm->flags &= ~PM_READONLY;
+ 		}
  		if (!asg->value)
  		    asg->value = dupstring(getsparam(asg->name));
  		unsetparam(asg->name);
***************
*** 1850,1857 ****
  		    addlinknode(locallist, ztrdup(asg->name));
  		} LASTALLOC;
  	    }
! 	    /* create a new node for a parameter with the flags in `on' minus the readonly flag */
  	    pm = createparam(ztrdup(asg->name), on & ~PM_READONLY);
  	    pm->ct = auxlen;
  	    if (func != BIN_EXPORT)
  		pm->level = locallevel;
--- 1854,1863 ----
  		    addlinknode(locallist, ztrdup(asg->name));
  		} LASTALLOC;
  	    }
! 	    /* create a new node for a parameter with the *
! 	     * flags in `on' minus the readonly flag      */
  	    pm = createparam(ztrdup(asg->name), on & ~PM_READONLY);
+ 	    DPUTS(!pm, "BUG: parameter not created");
  	    pm->ct = auxlen;
  	    if (func != BIN_EXPORT)
  		pm->level = locallevel;
*** Src/exec.c	1997/01/06 20:41:03	3.1.1.6
--- Src/exec.c	1997/01/07 16:09:45
***************
*** 1806,1813 ****
  
      if (removelist) {
  	/* remove temporary parameters */
! 	while ((s = (char *) ugetnode(removelist)))
! 	    unsetparam(s);
      }
  
      if (restorelist) {
--- 1806,1818 ----
  
      if (removelist) {
  	/* remove temporary parameters */
! 	while ((s = (char *) ugetnode(removelist))) {
! 	    if ((pm = (Param) paramtab->getnode(paramtab, s)) &&
! 		!(pm->flags & PM_SPECIAL)) {
! 		pm->flags &= ~PM_READONLY;
! 		unsetparam_pm(pm, 0);
! 	    }
! 	}
      }
  
      if (restorelist) {
*** params.c	1997/01/05 21:07:31	3.1.1.7
--- params.c	1997/01/07 16:56:19
***************
*** 173,187 ****
  	spec = oldpm && (oldpm->flags & PM_SPECIAL);
  
  	if ((oldpm && oldpm->level == locallevel) || spec) {
  	    pm = oldpm;
  	    pm->ct = 0;
  	    oldpm = pm->old;
! 	    pm->flags = (flags & (PM_EXPORTED | PM_LEFT | PM_RIGHT_B | PM_RIGHT_Z |
! 				  PM_LOWER | PM_UPPER | PM_READONLY | PM_TAGGED)) |
  		(pm->flags & (PM_SCALAR | PM_INTEGER | PM_ARRAY | PM_SPECIAL));
! 	    if (pm->ename && (altpm = (Param) paramtab->getnode(paramtab, pm->ename))) {
! 		altpm->flags &= ~(PM_UNSET | PM_EXPORTED | PM_LEFT | PM_RIGHT_B |
! 				  PM_RIGHT_Z | PM_LOWER | PM_UPPER | PM_READONLY | PM_TAGGED);
  	    }
  	} else {
  	    pm = (Param) zcalloc(sizeof *pm);
--- 173,192 ----
  	spec = oldpm && (oldpm->flags & PM_SPECIAL);
  
  	if ((oldpm && oldpm->level == locallevel) || spec) {
+ 	    if (oldpm && !(oldpm->flags & PM_UNSET))
+ 		return NULL;
  	    pm = oldpm;
  	    pm->ct = 0;
  	    oldpm = pm->old;
! 	    pm->flags = (flags & (PM_EXPORTED | PM_LEFT | PM_RIGHT_B |
! 				  PM_RIGHT_Z | PM_LOWER | PM_UPPER |
! 				  PM_READONLY | PM_TAGGED | PM_UNIQUE)) |
  		(pm->flags & (PM_SCALAR | PM_INTEGER | PM_ARRAY | PM_SPECIAL));
! 	    if (pm->ename &&
! 		(altpm = (Param) paramtab->getnode(paramtab, pm->ename))) {
! 		altpm->flags &= ~(PM_UNSET | PM_UNIQUE | PM_UPPER | PM_LEFT |
! 				  PM_RIGHT_B | PM_RIGHT_Z | PM_LOWER |
! 				  PM_READONLY | PM_TAGGED | PM_EXPORTED);
  	    }
  	} else {
  	    pm = (Param) zcalloc(sizeof *pm);
***************
*** 771,776 ****
--- 776,782 ----
  
      MUSTUSEHEAP("setstrvalue");
      if (v->pm->flags & PM_READONLY) {
+ 	zerr("read-only variable: %s", v->pm->nam, 0);
  	zsfree(val);
  	return;
      }
***************
*** 847,854 ****
  {
      char buf[DIGBUFSIZE];
  
!     if (v->pm->flags & PM_READONLY)
  	return;
      switch (PM_TYPE(v->pm->flags)) {
      case PM_SCALAR:
      case PM_ARRAY:
--- 853,862 ----
  {
      char buf[DIGBUFSIZE];
  
!     if (v->pm->flags & PM_READONLY) {
! 	zerr("read-only variable: %s", v->pm->nam, 0);
  	return;
+     }
      switch (PM_TYPE(v->pm->flags)) {
      case PM_SCALAR:
      case PM_ARRAY:
***************
*** 880,885 ****
--- 888,894 ----
  setarrvalue(Value v, char **val)
  {
      if (v->pm->flags & PM_READONLY) {
+ 	zerr("read-only variable: %s", v->pm->nam, 0);
  	freearray(val);
  	return;
      }
***************
*** 1060,1065 ****
--- 1069,1075 ----
      }
      if (!(v = getvalue(&s, 1))) {
  	pm = createparam(t, PM_INTEGER);
+ 	DPUTS(!pm, "BUG: parameter not created");
  	pm->u.val = val;
  	return pm;
      }
***************
*** 1088,1095 ****
      Param oldpm, altpm;
      int spec;
  
!     if ((pm->flags & PM_READONLY) && pm->level <= locallevel)
  	return;
      spec = (pm->flags & PM_SPECIAL) && !pm->level;
      switch (PM_TYPE(pm->flags)) {
      case PM_SCALAR:
--- 1098,1107 ----
      Param oldpm, altpm;
      int spec;
  
!     if ((pm->flags & PM_READONLY) && pm->level <= locallevel) {
! 	zerr("read-only variable: %s", pm->nam, 0);
  	return;
+     }
      spec = (pm->flags & PM_SPECIAL) && !pm->level;
      switch (PM_TYPE(pm->flags)) {
      case PM_SCALAR:


  reply	other threads:[~1997-01-07 17:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-01-07 13:56 Peter Stephenson
1997-01-07 17:09 ` Zoltan Hidvegi [this message]
1997-01-07 17:28   ` Peter Stephenson

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=199701071709.SAA24255@bolyai.cs.elte.hu \
    --to=hzoli@cs.elte.hu \
    --cc=pws@ifh.de \
    --cc=zsh-workers@math.gatech.edu \
    /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).