* infinite loop in prompt expansion
@ 2002-09-30 14:51 Laurent Wacrenier
2002-09-30 18:32 ` PATCH " Bart Schaefer
0 siblings, 1 reply; 4+ messages in thread
From: Laurent Wacrenier @ 2002-09-30 14:51 UTC (permalink / raw)
To: zsh-workers; +Cc: lwa
Prompt truncation may enter in infinite loop within litteral escape
sequence :
% print -P %/
/home/lwa
% print -P '%{%80<..<%/%}'
/home/lwa
% print -P '%8<..<%/'
..me/lwa
% print -P '%{%8<..<%/%}'
(don't give the hand back and spend all CPU time)
Tested on zsh 3.1.9 and 4.0.6
GDB output :
prompttrunc (arg=6, truncchar=134574132, doprint=1, endchar=0) at prompt.c:852
852 if (*p == Inpar)
(gdb) where
#0 prompttrunc (arg=6, truncchar=134574132, doprint=1, endchar=0)
at prompt.c:852
#1 0x280c0685 in putpromptchar (doprint=1, endchar=0) at prompt.c:443
#2 0x280bfcfc in promptexpand (s=0x80639a0 "%{%8<..<%/%}", ns=0,
rs=0x61 <Error reading address 0x61: Bad address>,
Rs=0x61 <Error reading address 0x61: Bad address>) at prompt.c:177
#3 0x2807eb8c in bin_print (name=0x8063970 "print", args=0xbfbff110,
ops=0xbfbff160 "", func=13) at builtin.c:2917
#4 0x2807768d in execbuiltin (args=0x8063940, bn=0x280db16c) at builtin.c:367
#5 0x2808889d in execcmd (state=0xbfbff470, input=0, output=0, how=18,
last1=2) at exec.c:2296
#6 0x28085cf4 in execpline2 (state=0xbfbff470, pcode=259, how=18, input=0,
output=0, last1=0) at exec.c:1201
#7 0x2808536d in execpline (state=0xbfbff470, slcode=97, how=18, last1=0)
at exec.c:991
#8 0x28084d3a in execlist (state=0xbfbff470, dont_change_job=0, exiting=0)
at exec.c:826
#9 0x28084a5f in execode (p=0x61, dont_change_job=97, exiting=97)
at exec.c:729
#10 0x280987b4 in loop (toplevel=1, justonce=0) at init.c:165
#11 0x2809b054 in zsh_main (argc=1, argv=0xbfbff544) at init.c:1215
#12 0x0804852b in exit ()
#13 0x08048455 in exit ()
(gdb) s
857 else if (w) {
(gdb)
852 if (*p == Inpar)
(gdb)
857 else if (w) {
(gdb)
852 if (*p == Inpar)
(gdb)
857 else if (w) {
(gdb)
852 if (*p == Inpar)
(gdb) print p
$1 = 0x8057034 "\211"
(gdb) print w
$2 = 0
^ permalink raw reply [flat|nested] 4+ messages in thread
* PATCH Re: infinite loop in prompt expansion
2002-09-30 14:51 infinite loop in prompt expansion Laurent Wacrenier
@ 2002-09-30 18:32 ` Bart Schaefer
2002-10-01 9:35 ` Laurent Wacrenier
0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2002-09-30 18:32 UTC (permalink / raw)
To: Laurent Wacrenier, zsh-workers
On Sep 30, 4:51pm, Laurent Wacrenier wrote:
} Subject: infinite loop in prompt expansion
}
} Prompt truncation may enter in infinite loop within litteral escape
} sequence :
}
} % print -P '%{%8<..<%/%}'
} (don't give the hand back and spend all CPU time)
It shouldn't infinte loop, but I'd like to point out that it also is not
intended to do anything useful.
%{ ... %} means that the string inside the braces is treated as zero width
for purposes of computing the size of the prompt. Truncating a zero width
string is a no-op.
Hence the fix (which is probably not going to make you happy) is this:
Index: prompt.c
===================================================================
RCS file: /extra/cvsroot/zsh/zsh-4.0/Src/prompt.c,v
retrieving revision 1.6
diff -c -r1.6 prompt.c
--- prompt.c 1 Sep 2002 16:47:38 -0000 1.6
+++ prompt.c 30 Sep 2002 18:31:15 -0000
@@ -856,6 +856,10 @@
addbufspc(1);
*bp++ = *fm++;
}
+ if (dontcount) {
+ bp = buf + w;
+ return 1;
+ }
if (!*fm)
return 0;
if (bp - buf == w && truncchar == ']') {
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: PATCH Re: infinite loop in prompt expansion
2002-09-30 18:32 ` PATCH " Bart Schaefer
@ 2002-10-01 9:35 ` Laurent Wacrenier
2002-10-02 7:18 ` Bart Schaefer
0 siblings, 1 reply; 4+ messages in thread
From: Laurent Wacrenier @ 2002-10-01 9:35 UTC (permalink / raw)
To: Bart Schaefer; +Cc: Laurent Wacrenier, zsh-workers
Le Lun 30 sep 18:32:30 2002, Bart Schaefer écrit:
> It shouldn't infinte loop, but I'd like to point out that it also is not
> intended to do anything useful.
This may have a sense within PS1 to set a xterm title or a terminal
status line.
> Hence the fix (which is probably not going to make you happy) is this:
Well... that's not what's wroten in the manual.
% print -P '%{%8<..<%/%}'
/home/lwa
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: PATCH Re: infinite loop in prompt expansion
2002-10-01 9:35 ` Laurent Wacrenier
@ 2002-10-02 7:18 ` Bart Schaefer
0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2002-10-02 7:18 UTC (permalink / raw)
To: Laurent Wacrenier; +Cc: zsh-workers
On Oct 1, 11:35am, Laurent Wacrenier wrote:
} Subject: Re: PATCH Re: infinite loop in prompt expansion
}
} Le Lun 30 sep 18:32:30 2002, Bart Schaefer écrit:
} > It shouldn't infinte loop, but I'd like to point out that it also is
} > not intended to do anything useful.
}
} This may have a sense within PS1 to set a xterm title or a terminal
} status line.
I guessed that was what you wanted, but it doesn't work.
Consider what happens when you put the %8<..< *outside* the %{ %} like so:
% print -P '%8<..<%{%/%}987654321'
../home/lwa654321
The manual says:
"The string within the braces should not change the cursor position."
Therefore zsh counts zero characters for everything from the %{ through
the matching %}, and applies the truncation to whatever comes after it.
Even when the %8<..< is put inside the braces, zsh is still counting zero
characters for everything through the ending %}. That's what confuses
the truncation code into going into an infinite loop.
} > Hence the fix (which is probably not going to make you happy) is this:
}
} Well... that's not what's wroten in the manual.
The manual says:
"The part of the prompt string to be truncated runs to the end of
the string, or to the end of the next enclosing group of the `%('
construct, or to the next truncation encountered at the same
grouping level (i.e. truncations inside a `%(' are separate), which
ever comes first."
Note that it *doesn't* say that it ends at the closing %} that matches a
preceding %{.
I think I've got a patch (by introducing Yet Another Global) that will
allow that to work, but I'd like to hear more zsh-workers' opinions first.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-10-02 7:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-09-30 14:51 infinite loop in prompt expansion Laurent Wacrenier
2002-09-30 18:32 ` PATCH " Bart Schaefer
2002-10-01 9:35 ` Laurent Wacrenier
2002-10-02 7:18 ` 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).