Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: prompt truncation with multibyte characters
- X-seq: zsh-workers 21890
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxxxxx>
- Subject: Re: PATCH: prompt truncation with multibyte characters
- Date: Wed, 19 Oct 2005 22:53:48 +0100
- In-reply-to: Your message of "Wed, 19 Oct 2005 22:15:40 +0200." <237967ef0510191315i6eab176apdb8bb6c2cf050551@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
> I get both freezes and crashes with this code, I have a backtrace for
> a crash at the end of the mail.
>..
> The difference being
> the one that crashes is one character longer. It also seems any name
> shorter than that works fine, and the ones longer crash, but i can't
> guarantee that. And yes, the short ones are still long enough to be
> truncated and seem to be so correctly.
Thanks. It was some overenthusiastic moving of a string so that it
stuck off the end of the allocated area; as the allocated area was
initially 255 bytes it didnʼt happen until the string was roughly half
that.
I spotted one almost entirely irrelevant warning and two apparent
inconsistencies around print -P and print -D while I was doing this.
Index: Src/builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.149
diff -u -r1.149 builtin.c
--- Src/builtin.c 17 Sep 2005 18:23:50 -0000 1.149
+++ Src/builtin.c 19 Oct 2005 21:49:24 -0000
@@ -3368,7 +3368,7 @@
*/
char *str = unmetafy(promptexpand(metafy(args[n], len[n],
META_NOALLOC), 0, NULL, NULL), &len[n]);
- args[n] = dupstring(str);
+ args[n] = dupstrpfx(str, len[n]);
free(str);
}
/* -D option -- interpret as a directory, and use ~ */
@@ -3378,9 +3378,9 @@
queue_signals();
d = finddir(args[n]);
if(d) {
- char *arg = zhalloc(strlen(args[n]) + 1);
- sprintf(arg, "~%s%s", d->nam,
- args[n] + strlen(d->dir));
+ int dirlen = strlen(d->dir);
+ char *arg = zhalloc(len[n] - dirlen + strlen(d->nam) + 2);
+ sprintf(arg, "~%s%s", d->nam, args[n] + dirlen);
args[n] = arg;
len[n] = strlen(args[n]);
}
Index: Src/prompt.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/prompt.c,v
retrieving revision 1.27
diff -u -r1.27 prompt.c
--- Src/prompt.c 19 Oct 2005 08:39:03 -0000 1.27
+++ Src/prompt.c 19 Oct 2005 21:49:25 -0000
@@ -1078,7 +1078,7 @@
int remw;
mbstate_t mbs;
- fulltextptr = fulltext = bp;
+ fulltextptr = fulltext = ptr + ntrunc;
memmove(fulltext, ptr, fullen);
fulltext[fullen] = '\0';
Index: Src/Zle/zle_utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/zle_utils.c,v
retrieving revision 1.28
diff -u -r1.28 zle_utils.c
--- Src/Zle/zle_utils.c 29 Sep 2005 17:32:38 -0000 1.28
+++ Src/Zle/zle_utils.c 19 Oct 2005 21:49:25 -0000
@@ -787,7 +787,8 @@
ZLE_CHAR_T c;
#ifdef ZLE_UNICODE_SUPPORT
char *umsg;
- int ulen, ret, width;
+ int ulen, ret;
+ size_t width;
mbstate_t ps;
#endif
--
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page still at http://www.pwstephenson.fsnet.co.uk/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author