From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: Zsh hackers list <zsh-workers@sunsite.dk>
Subject: Re: PATCH: prompt truncation with multibyte characters
Date: Wed, 19 Oct 2005 22:53:48 +0100 [thread overview]
Message-ID: <200510192153.j9JLrmLH023982@pwslaptop.csr.com> (raw)
In-Reply-To: Your message of "Wed, 19 Oct 2005 22:15:40 +0200." <237967ef0510191315i6eab176apdb8bb6c2cf050551@mail.gmail.com>
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2793 bytes --]
> 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@ntlworld.com>
Web page still at http://www.pwstephenson.fsnet.co.uk/
prev parent reply other threads:[~2005-10-19 21:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-19 8:33 Peter Stephenson
2005-10-19 20:15 ` Mikael Magnusson
2005-10-19 21:47 ` Mikael Magnusson
2005-10-19 21:53 ` Peter Stephenson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200510192153.j9JLrmLH023982@pwslaptop.csr.com \
--to=p.w.stephenson@ntlworld.com \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).