zsh-workers
 help / color / mirror / code / Atom feed
* Bug: Wrong completion of $(( $(!cmd
@ 2007-01-06  2:35 Jörg Sommer
  2007-01-22 23:43 ` Geoff Wing
  0 siblings, 1 reply; 7+ messages in thread
From: Jörg Sommer @ 2007-01-06  2:35 UTC (permalink / raw)
  To: zsh-workers

Hi,

% echo 12
12
% echo $(( $(!echo<TAB>
% echo $($(( $(echo 12
% echo $ZSH_VERSION 
4.3.2-dev-1
% dpkg -l zsh-beta
||/ Name           Version                Beschreibung
+++-==============-======================-============================================
ii  zsh-beta       4.3.2-dev-1+20070102-1 A shell with lots of features (dev tree)

Bye, Jörg.
-- 
Die NASA brauchte 12 Jahre um einen Kugelschreiber zu entwickeln, der
kopfüber, in der Schwerelosigkeit und unter Wasser schreiben kann.
Die Russen benutzten einfach einen Bleistift …


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

* Re: Bug: Wrong completion of $(( $(!cmd
  2007-01-06  2:35 Bug: Wrong completion of $(( $(!cmd Jörg Sommer
@ 2007-01-22 23:43 ` Geoff Wing
  2007-01-23 13:04   ` Peter Stephenson
  0 siblings, 1 reply; 7+ messages in thread
From: Geoff Wing @ 2007-01-22 23:43 UTC (permalink / raw)
  To: Zsh Hackers

On Saturday 2007-01-06 23:48 +1100, Jörg Sommer output:
:% echo 12
:12
:% echo $(( $(!echo<TAB>
:% echo $($(( $(echo 12

and inungetc() just after gives me 11 lines of
	Warning: backing up wrong character.

Regards,
Geoff


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

* Re: Bug: Wrong completion of $(( $(!cmd
  2007-01-22 23:43 ` Geoff Wing
@ 2007-01-23 13:04   ` Peter Stephenson
  2007-01-23 13:10     ` Peter Stephenson
  2007-01-23 15:23     ` Bart Schaefer
  0 siblings, 2 replies; 7+ messages in thread
From: Peter Stephenson @ 2007-01-23 13:04 UTC (permalink / raw)
  To: Zsh Hackers

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1173 bytes --]

Geoff Wing wrote:
> On Saturday 2007-01-06 23:48 +1100, Jörg Sommer output:
> :% echo 12
> :12
> :% echo $(( $(!echo<TAB>
> :% echo $($(( $(echo 12
> 
> and inungetc() just after gives me 11 lines of
> 	Warning: backing up wrong character.

The problem is somewhere here (in lex.c).  If dquote_parse() returns
non-zero it's an error indication, not a character, so the hungetc(c) is
definitely wrong in that case.  However, I don't understand the
intention behind error handling at this point.  I think we probably need
to return 1 earlier.


static int
cmd_or_math(int cs_type)
{
    int oldlen = len;
    int c;

    cmdpush(cs_type);
    c = dquote_parse(')', 0);
    cmdpop();
    *bptr = '\0';
    if (!c) {
	c = hgetc();
	if (c == ')')
	    return 1;
	hungetc(c);
	lexstop = 0;
	c = ')';
    }
    hungetc(c);
    lexstop = 0;
    while (len > oldlen) {
	len--;
	hungetc(itok(*--bptr) ? ztokens[*bptr - Pound] : *bptr);
    }
    hungetc('(');
    return 0;
}

-- 
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] 7+ messages in thread

* Re: Bug: Wrong completion of $(( $(!cmd
  2007-01-23 13:04   ` Peter Stephenson
@ 2007-01-23 13:10     ` Peter Stephenson
  2007-01-23 15:23     ` Bart Schaefer
  1 sibling, 0 replies; 7+ messages in thread
From: Peter Stephenson @ 2007-01-23 13:10 UTC (permalink / raw)
  To: Zsh Hackers

Peter Stephenson <pws@csr.com> wrote:
> Geoff Wing wrote:
> > On Saturday 2007-01-06 23:48 +1100, J_rg Sommer output:
> > :% echo 12
> > :12
> > :% echo $(( $(!echo<TAB>
> > :% echo $($(( $(echo 12
> > 
> > and inungetc() just after gives me 11 lines of
> > 	Warning: backing up wrong character.
> 
> The problem is somewhere here (in lex.c).  If dquote_parse() returns
> non-zero it's an error indication, not a character, so the hungetc(c) is
> definitely wrong in that case.  However, I don't understand the
> intention behind error handling at this point.  I think we probably need
> to return 1 earlier.

Is it this simple?  Seems to do the trick...

Index: Src/lex.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/lex.c,v
retrieving revision 1.37
diff -u -r1.37 lex.c
--- Src/lex.c	19 Jan 2007 21:36:03 -0000	1.37
+++ Src/lex.c	23 Jan 2007 13:08:47 -0000
@@ -542,14 +542,14 @@
     c = dquote_parse(')', 0);
     cmdpop();
     *bptr = '\0';
-    if (!c) {
-	c = hgetc();
-	if (c == ')')
-	    return 1;
-	hungetc(c);
-	lexstop = 0;
-	c = ')';
-    }
+    if (c)
+	return 1;
+    c = hgetc();
+    if (c == ')')
+	return 1;
+    hungetc(c);
+    lexstop = 0;
+    c = ')';
     hungetc(c);
     lexstop = 0;
     while (len > oldlen) {

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


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php

To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview


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

* Re: Bug: Wrong completion of $(( $(!cmd
  2007-01-23 13:04   ` Peter Stephenson
  2007-01-23 13:10     ` Peter Stephenson
@ 2007-01-23 15:23     ` Bart Schaefer
  2007-01-23 15:35       ` Peter Stephenson
  1 sibling, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2007-01-23 15:23 UTC (permalink / raw)
  To: Peter Stephenson, Zsh Hackers

On Jan 23,  1:04pm, Peter Stephenson wrote:
}
} The problem is somewhere here (in lex.c). If dquote_parse() returns
} non-zero it's an error indication, not a character, so the hungetc(c)
} is definitely wrong in that case.

I don't think that's true.  If you look at the tail end of dquote_parse()
you'll see that if lexstop is false the return value of dquote_parse() is
overloaded -- it's both an error indication AND the most recently read
character from the input stream.  That's what hungetc() is trying to put
back in that spot in cmd_or_math().

That doesn't make it correct, but that's what's going on.  There must be
(or have been at some past time) some other reason higher up the parse
tree why that final character needed to be retained.


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

* Re: Bug: Wrong completion of $(( $(!cmd
  2007-01-23 15:23     ` Bart Schaefer
@ 2007-01-23 15:35       ` Peter Stephenson
  2007-01-23 15:47         ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Peter Stephenson @ 2007-01-23 15:35 UTC (permalink / raw)
  To: Zsh Hackers

Bart Schaefer wrote:
> On Jan 23,  1:04pm, Peter Stephenson wrote:
> }
> } The problem is somewhere here (in lex.c). If dquote_parse() returns
> } non-zero it's an error indication, not a character, so the hungetc(c)
> } is definitely wrong in that case.
> 
> I don't think that's true.

I presume you mean the second statement.  If you've got any evidence
against the first statement I'd like to see it.

> If you look at the tail end of dquote_parse()
> you'll see that if lexstop is false the return value of dquote_parse() is
> overloaded -- it's both an error indication AND the most recently read
> character from the input stream.  That's what hungetc() is trying to put
> back in that spot in cmd_or_math().
> 
> That doesn't make it correct, but that's what's going on.  There must be
> (or have been at some past time) some other reason higher up the parse
> tree why that final character needed to be retained.

I looked a bit further and it seems it's used in gettokstr() to
hungetc() a character when we have an error.  I don't understand what
that buys when we can't parse the input anyway, particularly since we
don't even know if it's a valid character because of the other way of
setting the value; could it have been a hack to get history lines to be
stored properly after an error?  I recall we improved that at some
point, so this hack may not be necessary.

I traced it (the "err = c" thing in dquote_parse()) back in the code to
3.0.0, which is before the use in cmd_or_math() that is causing the
problem, so it wasn't introduced specifically for that, and
cmd_or_math() was roughly the way it now is right back in 3.0.8.
Consequently (although what you say is true) I don't see anything wrong
with the proposed change.

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


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php

To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview


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

* Re: Bug: Wrong completion of $(( $(!cmd
  2007-01-23 15:35       ` Peter Stephenson
@ 2007-01-23 15:47         ` Bart Schaefer
  0 siblings, 0 replies; 7+ messages in thread
From: Bart Schaefer @ 2007-01-23 15:47 UTC (permalink / raw)
  To: Zsh Hackers

On Jan 23,  3:35pm, Peter Stephenson wrote:
} Subject: Re: Bug: Wrong completion of $(( $(!cmd
}
} Bart Schaefer wrote:
} > On Jan 23,  1:04pm, Peter Stephenson wrote:
} > }
} > } The problem is somewhere here (in lex.c). If dquote_parse() returns
} > } non-zero it's an error indication, not a character, so the hungetc(c)
} > } is definitely wrong in that case.
} > 
} > I don't think that's true.
} 
} I presume you mean the second statement.

Yes.

} Consequently (although what you say is true) I don't see anything wrong
} with the proposed change.

OK.  Thanks for looking further.


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

end of thread, other threads:[~2007-01-23 15:47 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-06  2:35 Bug: Wrong completion of $(( $(!cmd Jörg Sommer
2007-01-22 23:43 ` Geoff Wing
2007-01-23 13:04   ` Peter Stephenson
2007-01-23 13:10     ` Peter Stephenson
2007-01-23 15:23     ` Bart Schaefer
2007-01-23 15:35       ` Peter Stephenson
2007-01-23 15:47         ` Bart Schaefer

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