* Problem with unicode string length zsh segfaults
@ 2008-10-30 14:03 Kazuo Teramoto
2008-10-30 14:25 ` Mikael Magnusson
2008-10-30 15:25 ` Peter Stephenson
0 siblings, 2 replies; 3+ messages in thread
From: Kazuo Teramoto @ 2008-10-30 14:03 UTC (permalink / raw)
To: zsh-workers
Hello!
(My first email to list, I subscribed to workers, but I send this type
of msg to workers or users?)
I'm having a problem with string size and unicode chars. I'm using
string size in my prompt theme, I'm using the following code to
calculate the string size of pwd:
${#${(%):-%~}}
But sometimes this got the number wrong e.g. I have a dir named
'~/Music/梶浦由記' (Yuki Kajiura composer of Noir anime soundtrack) the
code above give 13 chars but it have 12 chars (count or using "print
-Pn '%~'|wc -m" and wc -c give 20 bytes).
And if I cd on this dir my prompt get wrong by 3 chars (e.g. on a
prompt like adams2 the first line is bigger by 3 chars)
The problem is greater for a dir named 'Пётр Ильич Чайковский' (Pyotr
Il'yich Tchaikovsky, Russian composer) if I cd on it and execute the
code above I get
zsh: unmatched '
zsh: parse error in command substitution
and if I try this several times (repeat this command) my zsh segfaults:
1: subst.c:222: BUG: parse error in command substitution
Program received signal SIGSEGV, Segmentation fault.
0x000000000047e4b4 in ?? ()
(gdb) bt
#0 0x000000000047e4b4 in ?? ()
#1 0x0000000000482cee in prefork ()
#2 0x00000000004843ea in ?? ()
#3 0x000000000047e694 in ?? ()
#4 0x0000000000482cee in prefork ()
#5 0x000000000042a488 in ?? ()
#6 0x000000000042c948 in ?? ()
#7 0x000000000042cce0 in ?? ()
#8 0x000000000042e02d in execlist ()
#9 0x000000000042e275 in execode ()
#10 0x000000000042e36c in runshfunc ()
#11 0x000000000042e72b in doshfunc ()
#12 0x000000000042e9b0 in ?? ()
#13 0x000000000042c604 in ?? ()
#14 0x000000000042c948 in ?? ()
#15 0x000000000042cce0 in ?? ()
#16 0x000000000042e02d in execlist ()
#17 0x000000000042e275 in execode ()
#18 0x000000000042e36c in runshfunc ()
#19 0x000000000042e72b in doshfunc ()
#20 0x0000000000487db6 in callhookfunc ()
#21 0x000000000048f593 in preprompt ()
#22 0x000000000043ee6c in loop ()
#23 0x0000000000441fe7 in zsh_main ()
#24 0x00007f9c3153c3f6 in __libc_start_main () from /lib/libc.so.6
#25 0x000000000040f939 in _start ()
--
«Dans la vie, rien n'est à craindre, tout est à comprendre»
Marie Sklodowska Curie.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Problem with unicode string length zsh segfaults
2008-10-30 14:03 Problem with unicode string length zsh segfaults Kazuo Teramoto
@ 2008-10-30 14:25 ` Mikael Magnusson
2008-10-30 15:25 ` Peter Stephenson
1 sibling, 0 replies; 3+ messages in thread
From: Mikael Magnusson @ 2008-10-30 14:25 UTC (permalink / raw)
To: Kazuo Teramoto; +Cc: zsh-workers
2008/10/30 Kazuo Teramoto <kaz.rag@gmail.com>:
> Hello!
> (My first email to list, I subscribed to workers, but I send this type
> of msg to workers or users?)
To workers, and it's also a pretty good idea to say which version of
zsh you're using.
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Problem with unicode string length zsh segfaults
2008-10-30 14:03 Problem with unicode string length zsh segfaults Kazuo Teramoto
2008-10-30 14:25 ` Mikael Magnusson
@ 2008-10-30 15:25 ` Peter Stephenson
1 sibling, 0 replies; 3+ messages in thread
From: Peter Stephenson @ 2008-10-30 15:25 UTC (permalink / raw)
To: Kazuo Teramoto; +Cc: zsh-workers
On Thu, 30 Oct 2008 12:03:22 -0200
"Kazuo Teramoto" <kaz.rag@gmail.com> wrote:
> Hello!
> (My first email to list, I subscribed to workers, but I send this type
> of msg to workers or users?)
Yes, zsh-workers is correct.
> I'm having a problem with string size and unicode chars. I'm using
> string size in my prompt theme, I'm using the following code to
> calculate the string size of pwd:
>
> ${#${(%):-%~}}
>
> But sometimes this got the number wrong e.g. I have a dir named
> '~/Music/梶浦由記' (Yuki Kajiura composer of Noir anime soundtrack) the
> code above give 13 chars but it have 12 chars (count or using "print
> -Pn '%~'|wc -m" and wc -c give 20 bytes).
>
> And if I cd on this dir my prompt get wrong by 3 chars (e.g. on a
> prompt like adams2 the first line is bigger by 3 chars)
>
> The problem is greater for a dir named 'Пётр Ильич Чайковский' (Pyotr
> Il'yich Tchaikovsky, Russian composer) if I cd on it and execute the
> code above I get
>
> zsh: unmatched '
> zsh: parse error in command substitution
>
> and if I try this several times (repeat this command) my zsh segfaults:
>
> 1: subst.c:222: BUG: parse error in command substitution
Thanks for the report.
Same bug in each case; it's taken surprisingly long to find and I can't
understand how we thought the code should look like that.
I found a similar bug in new code at the same time.
Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.89
diff -u -r1.89 subst.c
--- Src/subst.c 27 Sep 2008 20:58:28 -0000 1.89
+++ Src/subst.c 30 Oct 2008 15:22:34 -0000
@@ -2738,8 +2738,8 @@
char *tmps;
unmetafy(*ap, &len);
untokenize(*ap);
- tmps = unmetafy(promptexpand(metafy(*ap, len, META_NOALLOC),
- 0, NULL, NULL, NULL), &len);
+ tmps = promptexpand(metafy(*ap, len, META_NOALLOC),
+ 0, NULL, NULL, NULL);
*ap = dupstring(tmps);
free(tmps);
}
@@ -2749,8 +2749,8 @@
val = dupstring(val), copied = 1;
unmetafy(val, &len);
untokenize(val);
- tmps = unmetafy(promptexpand(metafy(val, len, META_NOALLOC),
- 0, NULL, NULL, NULL), &len);
+ tmps = promptexpand(metafy(val, len, META_NOALLOC),
+ 0, NULL, NULL, NULL);
val = dupstring(tmps);
free(tmps);
}
Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.205
diff -u -r1.205 utils.c
--- Src/utils.c 30 Oct 2008 14:04:31 -0000 1.205
+++ Src/utils.c 30 Oct 2008 15:22:34 -0000
@@ -857,7 +857,9 @@
scanhashtable(nameddirtab, 0, 0, 0, finddir_scan, 0);
if (func) {
- char **ares = subst_string_by_func(func, "d", finddir_full);
+ char *dir_meta = metafy(finddir_full, strlen(finddir_full),
+ META_ALLOC);
+ char **ares = subst_string_by_func(func, "d", dir_meta);
int len;
if (ares && arrlen(ares) >= 2 &&
(len = (int)zstrtol(ares[1], NULL, 10)) > finddir_best) {
@@ -868,6 +870,8 @@
finddir_last->diff = len - strlen(finddir_last->node.nam);
finddir_best = len;
}
+ if (dir_meta != finddir_full)
+ zsfree(dir_meta);
}
return finddir_last;
Index: Test/D07multibyte.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D07multibyte.ztst,v
retrieving revision 1.27
diff -u -r1.27 D07multibyte.ztst
--- Test/D07multibyte.ztst 18 Oct 2008 16:03:18 -0000 1.27
+++ Test/D07multibyte.ztst 30 Oct 2008 15:22:34 -0000
@@ -403,3 +403,10 @@
0:Backslashes and metafied characters in patterns
>Matched against glob/()Ą/*
>Matched against glob/()Ā/*
+
+ mkdir 梶浦由記 'Пётр Ильич Чайковский'
+ (cd 梶浦由記; print ${${(%):-%~}:t})
+ (cd 'Пётр Ильич Чайковский'; print ${${(%):-%~}:t})
+0:Metafied characters in prompt expansion
+>梶浦由記
+>Пётр Ильич Чайковский
--
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] 3+ messages in thread
end of thread, other threads:[~2008-10-30 15:26 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-30 14:03 Problem with unicode string length zsh segfaults Kazuo Teramoto
2008-10-30 14:25 ` Mikael Magnusson
2008-10-30 15:25 ` Peter Stephenson
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).