zsh-workers
 help / color / mirror / code / Atom feed
* zsh crash on assignment to $options
@ 2009-01-08 11:39 Andrey Borzenkov
  2009-01-08 12:09 ` Richard Hartmann
  2009-01-08 13:04 ` Peter Stephenson
  0 siblings, 2 replies; 4+ messages in thread
From: Andrey Borzenkov @ 2009-01-08 11:39 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1530 bytes --]

I got this on after

typeset -A __opts
__opts=${(kv)options}
echo ${options[shwordsplit]}
emulate -R sh
echo ${options[shwordsplit]}
options=$__opts

Stack trace:

(gdb) bt
#0  0x08098427 in setstrvalue (v=0xbfbf1fbc,
    val=0x9028050 "autolist on printexitvalue off kshzerosubscript off 
histreduceblanks off chaselinks off extendedglob off histnostore off 
automenu on globcomplete off unset on listpacked off promptsubst off 
shwordspli"...)
    at params.c:2273
#1  0x0809cf1a in assignsparam (s=0xb80b82cb "",
    val=0x9028050 "autolist on printexitvalue off kshzerosubscript off 
histreduceblanks off chaselinks off extendedglob off histnostore off 
automenu on globcomplete off unset on listpacked off promptsubst off 
shwordspli"...,
    flags=<value optimized out>) at params.c:2617
#2  0x08065c26 in addvars (state=0xbfbf211c, pc=<value optimized out>,
    addflags=<value optimized out>) at exec.c:2112
#3  0x08065e7b in execsimple (state=0xbfbf211c) at exec.c:1002
#4  0x0806c426 in execlist (state=0xbfbf211c, dont_change_job=0, 
exiting=0)
    at exec.c:1112
#5  0x0806cb1e in execode (p=0xb80b8280, dont_change_job=0, exiting=0)
    at exec.c:975
#6  0x0807e08c in loop (toplevel=1, justonce=0) at init.c:181
#7  0x0807f726 in zsh_main (argc=2, argv=0xbfbf2224) at init.c:1406
#8  0x08052a8f in main (argc=0, argv=0x9025050) at ./main.c:93


Using ${(kv)__opts[*]} works (and above is likely an error) still shell 
probably should not react that badly to simple user error.

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

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

* Re: zsh crash on assignment to $options
  2009-01-08 11:39 zsh crash on assignment to $options Andrey Borzenkov
@ 2009-01-08 12:09 ` Richard Hartmann
  2009-01-08 13:04 ` Peter Stephenson
  1 sibling, 0 replies; 4+ messages in thread
From: Richard Hartmann @ 2009-01-08 12:09 UTC (permalink / raw)
  To: Andrey Borzenkov; +Cc: zsh-workers

On Thu, Jan 8, 2009 at 12:39, Andrey Borzenkov <arvidjaar@newmail.ru> wrote:

> I got this on after

Confirmed for CVS 1230

richih@titanium 4.3.9-dev-1-cvs1230 ~ % zsh-beta -f
titanium% echo $ZSH_VERSION
4.3.9-dev-1-cvs1230
titanium%
titanium% typeset -A __opts
titanium% __opts=${(kv)options}
titanium% echo ${options[shwordsplit]}
off
titanium% emulate -R sh
%m%# echo ${options[shwordsplit]}
on
%m%# options=$__opts
[1]    7247 segmentation fault  zsh-beta -f
richih@titanium 4.3.9-dev-1-cvs1230 ~ % echo $?
139
richih@titanium 4.3.9-dev-1-cvs1230 ~ %


Richard


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

* Re: zsh crash on assignment to $options
  2009-01-08 11:39 zsh crash on assignment to $options Andrey Borzenkov
  2009-01-08 12:09 ` Richard Hartmann
@ 2009-01-08 13:04 ` Peter Stephenson
  2009-01-08 15:50   ` Richard Hartmann
  1 sibling, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2009-01-08 13:04 UTC (permalink / raw)
  To: zsh-workers

On Thu, 8 Jan 2009 14:39:32 +0300
Andrey Borzenkov <arvidjaar@newmail.ru> 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@csr.com>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


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

* Re: zsh crash on assignment to $options
  2009-01-08 13:04 ` Peter Stephenson
@ 2009-01-08 15:50   ` Richard Hartmann
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Hartmann @ 2009-01-08 15:50 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-workers

On Thu, Jan 8, 2009 at 14:04, Peter Stephenson <pws@csr.com> wrote:

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

I would suggest adding test cases like the one which prompted the diff
to the test suite. As unlikely as regressions in that area may be, it's a
relatively cheap (read: easy) way to build a library of what I like to call
nut-case tests.


Richard


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

end of thread, other threads:[~2009-01-08 15:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-08 11:39 zsh crash on assignment to $options Andrey Borzenkov
2009-01-08 12:09 ` Richard Hartmann
2009-01-08 13:04 ` Peter Stephenson
2009-01-08 15:50   ` Richard Hartmann

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