zsh-workers
 help / color / mirror / code / Atom feed
* typeset -T crash
@ 2015-08-05 17:59 Mikael Magnusson
  2015-08-05 20:04 ` Bart Schaefer
  2015-08-09 17:56 ` Peter Stephenson
  0 siblings, 2 replies; 6+ messages in thread
From: Mikael Magnusson @ 2015-08-05 17:59 UTC (permalink / raw)
  To: zsh workers

typeset -T i j k; typeset -T j i k

Program received signal SIGSEGV, Segmentation fault.
bin_typeset (name=0x7ffff7ff67e8 "typeset", argv=0x7ffff7ff6828, assigns=0x0,
    ops=0x7fffffffce20, func=0) at builtin.c:2680
2680                tdp->joinchar = joinchar;
(gdb) bt
#0  bin_typeset (name=0x7ffff7ff67e8 "typeset", argv=0x7ffff7ff6828,
assigns=0x0,
    ops=0x7fffffffce20, func=0) at builtin.c:2680
#1  0x000000000041da86 in execbuiltin (args=args@entry=0x7ffff7ff6758,
    assigns=assigns@entry=0x0, bn=bn@entry=0x6ae640 <builtins+4096>)
at builtin.c:480
#2  0x000000000042c357 in execcmd (state=state@entry=0x7fffffffd460,
input=input@entry=0,
    output=output@entry=0, how=<optimized out>, how@entry=18, last1=1)
at exec.c:3622
#3  0x000000000042c871 in execpline2 (state=state@entry=0x7fffffffd460,
    pcode=pcode@entry=131, how=how@entry=18, input=0, output=0,
last1=last1@entry=1)
    at exec.c:1724
#4  0x000000000042ce7b in execpline (state=state@entry=0x7fffffffd460,
    slcode=<optimized out>, how=how@entry=18, last1=1) at exec.c:1507
#5  0x000000000042dcda in execlist (state=state@entry=0x7fffffffd460,
    dont_change_job=dont_change_job@entry=0, exiting=exiting@entry=1)
at exec.c:1277
#6  0x000000000042e1a0 in execode (p=0x7ffff7ff6588,
    dont_change_job=dont_change_job@entry=0, exiting=exiting@entry=1,
    context=context@entry=0x492af7 "cmdarg") at exec.c:1074
#7  0x000000000042e235 in execstring (s=0x7fffffffda66 "typeset -T i j
k; typeset -T j i k",
    dont_change_job=dont_change_job@entry=0, exiting=exiting@entry=1,
    context=context@entry=0x492af7 "cmdarg") at exec.c:1040
(gdb) p tdp
$1 = (struct tieddata *) 0x0


I don't know what any of the things are, and the comment looks like PWS does.

I would have thought the earlier checks that i/j and j/i are scalar /
array respectively respectively would have stopped the code until we
got to this point though?

-- 
Mikael Magnusson


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

* Re: typeset -T crash
  2015-08-05 17:59 typeset -T crash Mikael Magnusson
@ 2015-08-05 20:04 ` Bart Schaefer
  2015-08-05 20:41   ` Mikael Magnusson
  2015-08-09 17:56 ` Peter Stephenson
  1 sibling, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2015-08-05 20:04 UTC (permalink / raw)
  To: zsh workers

On Aug 5,  7:59pm, Mikael Magnusson wrote:
} Subject: typeset -T crash
}
} typeset -T i j k; typeset -T j i k

Something like this?

diff --git a/Src/builtin.c b/Src/builtin.c
index a08a7d4..b32d679 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2680,10 +2680,15 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
 		     */
 		    struct tieddata *tdp = (struct tieddata*)pm->u.data;
 		    /* Update join character */
-		    tdp->joinchar = joinchar;
-		    if (asg0.value.scalar)
-			setsparam(asg0.name, ztrdup(asg0.value.scalar));
-		    return 0;
+		    if (tdp) {
+			tdp->joinchar = joinchar;
+			if (asg0.value.scalar)
+			    setsparam(asg0.name, ztrdup(asg0.value.scalar));
+			return 0;
+		    } else {
+			zwarnnam(name, "can't tie already tied array: %s",
+				 asg0.name);
+		    }
 		} else {
 		    zwarnnam(name, "can't tie already tied scalar: %s",
 			    asg0.name);


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

* Re: typeset -T crash
  2015-08-05 20:04 ` Bart Schaefer
@ 2015-08-05 20:41   ` Mikael Magnusson
  2015-08-06  0:35     ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Mikael Magnusson @ 2015-08-05 20:41 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh workers

On Wed, Aug 5, 2015 at 10:04 PM, Bart Schaefer
<schaefer@brasslantern.com> wrote:
> On Aug 5,  7:59pm, Mikael Magnusson wrote:
> } Subject: typeset -T crash
> }
> } typeset -T i j k; typeset -T j i k
>
> Something like this?

Well, I suppose just checking tdp there works, but should we be
getting there at all? The error message also seems wrong since while
the array is already tied, we're trying to tie it as a scalar to its
tied scalar passed in the array position... (And in case anyone
overlooked it, the i and j are swapped in the above command, I could
probably have picked better letters).

> diff --git a/Src/builtin.c b/Src/builtin.c
> index a08a7d4..b32d679 100644
> --- a/Src/builtin.c
> +++ b/Src/builtin.c
> @@ -2680,10 +2680,15 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
>                      */
>                     struct tieddata *tdp = (struct tieddata*)pm->u.data;
>                     /* Update join character */
> -                   tdp->joinchar = joinchar;
> -                   if (asg0.value.scalar)
> -                       setsparam(asg0.name, ztrdup(asg0.value.scalar));
> -                   return 0;
> +                   if (tdp) {
> +                       tdp->joinchar = joinchar;
> +                       if (asg0.value.scalar)
> +                           setsparam(asg0.name, ztrdup(asg0.value.scalar));
> +                       return 0;
> +                   } else {
> +                       zwarnnam(name, "can't tie already tied array: %s",
> +                                asg0.name);
> +                   }
>                 } else {
>                     zwarnnam(name, "can't tie already tied scalar: %s",
>                             asg0.name);



-- 
Mikael Magnusson


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

* Re: typeset -T crash
  2015-08-05 20:41   ` Mikael Magnusson
@ 2015-08-06  0:35     ` Bart Schaefer
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2015-08-06  0:35 UTC (permalink / raw)
  To: zsh workers

On Aug 5, 10:41pm, Mikael Magnusson wrote:
}
} Well, I suppose just checking tdp there works, but should we be
} getting there at all?

I suspect this is happening because getasg() always sets asg.is_array = 0,
then.  The only place is_array is assigned 1 is in execcmd() in the
postassigns block, and then only if there's a paren after the '='.

There isn't any other test based on the fetched param for whether the
first argument after -T is not scalar, as far as I can tell.


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

* Re: typeset -T crash
  2015-08-05 17:59 typeset -T crash Mikael Magnusson
  2015-08-05 20:04 ` Bart Schaefer
@ 2015-08-09 17:56 ` Peter Stephenson
  2015-08-09 19:31   ` Mikael Magnusson
  1 sibling, 1 reply; 6+ messages in thread
From: Peter Stephenson @ 2015-08-09 17:56 UTC (permalink / raw)
  To: zsh workers

On Wed, 5 Aug 2015 19:59:31 +0200
Mikael Magnusson <mikachu@gmail.com> wrote:
> typeset -T i j k; typeset -T j i k

Surely the right fix is something like this?

pws

diff --git a/Src/builtin.c b/Src/builtin.c
index 34bad03..c63be7e 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -2674,7 +2674,9 @@ bin_typeset(char *name, char **argv, LinkList assigns, Options ops, int func)
 	    && (locallevel == pm->level || !(on & PM_LOCAL))) {
 	    if (pm->node.flags & PM_TIED) {
 		unqueue_signals();
-		if (!strcmp(asg->name, pm->ename)) {
+		if (PM_TYPE(pm->node.flags) != PM_SCALAR) {
+		    zwarnnam(name, "already tied as non-scalar: %s", asg0.name);
+		} else if (!strcmp(asg->name, pm->ename)) {
 		    /*
 		     * Already tied in the fashion requested.
 		     */
diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst
index 0a9e253..c7d506a 100644
--- a/Test/D04parameter.ztst
+++ b/Test/D04parameter.ztst
@@ -1069,6 +1069,11 @@
 >a:b a b
 >x:y:z
 
+  typeset -T tied1 tied2 +
+  typeset -T tied2 tied1 +
+1:Attempts to swap tied variables are safe but futile
+?(eval):typeset:2: already tied as non-scalar: tied2
+
   string='look for a match in here'
   if [[ ${string%%(#b)(match)*} = "look for a " ]]; then
     print $match[1] $mbegin[1] $mend[1] $string[$mbegin[1],$mend[1]]


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

* Re: typeset -T crash
  2015-08-09 17:56 ` Peter Stephenson
@ 2015-08-09 19:31   ` Mikael Magnusson
  0 siblings, 0 replies; 6+ messages in thread
From: Mikael Magnusson @ 2015-08-09 19:31 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh workers

On Sun, Aug 9, 2015 at 7:56 PM, Peter Stephenson
<p.w.stephenson@ntlworld.com> wrote:
> On Wed, 5 Aug 2015 19:59:31 +0200
> Mikael Magnusson <mikachu@gmail.com> wrote:
>> typeset -T i j k; typeset -T j i k
>
> Surely the right fix is something like this?

It certainly looks plausible enough.

-- 
Mikael Magnusson


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

end of thread, other threads:[~2015-08-09 19:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-05 17:59 typeset -T crash Mikael Magnusson
2015-08-05 20:04 ` Bart Schaefer
2015-08-05 20:41   ` Mikael Magnusson
2015-08-06  0:35     ` Bart Schaefer
2015-08-09 17:56 ` Peter Stephenson
2015-08-09 19:31   ` Mikael Magnusson

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