Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh crash on assignment to $options



On Thu, 8 Jan 2009 14:39:32 +0300
Andrey Borzenkov <arvidjaar@xxxxxxxxxx> wrote:
> I got this on after
> 
> typeset -A __opts
> __opts=${(kv)options}
> echo ${options[shwordsplit]}
> emulate -R sh
> echo ${options[shwordsplit]}
> options=$__opts

The following should be a safe fix, but there may be similar problems it
doesn't pick up.  I'm happy to receive reports from pedantic tests of code
that's never going to work (but shouldn't crash either).  The stuff to do
with "foundparam" isn't particularly elegant (or documented).

Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.150
diff -u -r1.150 params.c
--- Src/params.c	23 Oct 2008 00:48:59 -0000	1.150
+++ Src/params.c	8 Jan 2009 12:59:36 -0000
@@ -498,7 +498,7 @@
 static Param foundparam;     
 
 /**/
-void
+static void
 scanparamvals(HashNode hn, int flags)
 {
     struct value v;
@@ -538,6 +538,7 @@
 	    --numparamvals;	/* Value didn't match, discard key */
     } else
 	++numparamvals;
+    foundparam = NULL;
 }
 
 /**/
@@ -2270,7 +2271,15 @@
 	break;
     case PM_HASHED:
         {
-	    foundparam->gsu.s->setfn(foundparam, val);
+	    if (foundparam == NULL)
+	    {
+		zerr("%s: attempt to set associative array to scalar",
+		     v->pm->node.nam);
+		zsfree(val);
+		return;
+	    }
+	    else
+		foundparam->gsu.s->setfn(foundparam, val);
         }
 	break;
     }

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



Messages sorted by: Reverse Date, Date, Thread, Author