From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9410 invoked from network); 19 Oct 2005 21:54:04 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 19 Oct 2005 21:54:04 -0000 Received: (qmail 54385 invoked from network); 19 Oct 2005 21:53:58 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 19 Oct 2005 21:53:58 -0000 Received: (qmail 24068 invoked by alias); 19 Oct 2005 21:53:55 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21890 Received: (qmail 24057 invoked from network); 19 Oct 2005 21:53:54 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 19 Oct 2005 21:53:54 -0000 Received: (qmail 54085 invoked from network); 19 Oct 2005 21:53:54 -0000 Received: from mta09-winn.ispmail.ntl.com (81.103.221.49) by a.mx.sunsite.dk with SMTP; 19 Oct 2005 21:53:53 -0000 Received: from aamta09-winn.ispmail.ntl.com ([81.103.221.35]) by mta09-winn.ispmail.ntl.com with ESMTP id <20051019215352.YKLY8609.mta09-winn.ispmail.ntl.com@aamta09-winn.ispmail.ntl.com> for ; Wed, 19 Oct 2005 22:53:52 +0100 Received: from pwslaptop.csr.com ([81.105.238.64]) by aamta09-winn.ispmail.ntl.com with ESMTP id <20051019215352.LMON6564.aamta09-winn.ispmail.ntl.com@pwslaptop.csr.com> for ; Wed, 19 Oct 2005 22:53:52 +0100 Received: from pwslaptop.csr.com (pwslaptop.csr.com [127.0.0.1]) by pwslaptop.csr.com (8.13.4/8.13.4) with ESMTP id j9JLro3m023985 for ; Wed, 19 Oct 2005 22:53:50 +0100 Received: from pwslaptop.csr.com (pws@localhost) by pwslaptop.csr.com (8.13.4/8.13.4/Submit) with ESMTP id j9JLrmLH023982 for ; Wed, 19 Oct 2005 22:53:50 +0100 Message-Id: <200510192153.j9JLrmLH023982@pwslaptop.csr.com> X-Authentication-Warning: pwslaptop.csr.com: pws owned process doing -bs From: Peter Stephenson To: Zsh hackers list Subject: Re: PATCH: prompt truncation with multibyte characters In-Reply-To: Your message of "Wed, 19 Oct 2005 22:15:40 +0200." <237967ef0510191315i6eab176apdb8bb6c2cf050551@mail.gmail.com> Date: Wed, 19 Oct 2005 22:53:48 +0100 X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.4 > 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 Web page still at http://www.pwstephenson.fsnet.co.uk/