zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <Peter.Stephenson@csr.com>
To: <zsh-workers@zsh.org>
Subject: Re: PATCH: Fix multibyte memory allocation in `wcs_ztrdup()'
Date: Mon, 28 Feb 2011 11:55:10 +0000	[thread overview]
Message-ID: <20110228115510.29590f1d@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <1298889300-29679-1-git-send-email-ft@bewatermyfriend.org>

On Mon, 28 Feb 2011 11:35:00 +0100
Frank Terbeck <ft@bewatermyfriend.org> wrote:
> This was spotted by Thorsten Glaser from the mirbsd project.
> 
> `zalloc()' uses malloc(3) to allocate memory. wcslen(3) returns the
> number of multibyte *characters* in a given string (N). The
> destination string will have to be able to store N+1 wchar_ts, not
> N+1 bytes.

Thanks... and it needs to be a wide NULL (L'0'), too, so another
lot of parentheses is needed.

Index: Src/string.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/string.c,v
retrieving revision 1.10
diff -p -u -r1.10 string.c
--- Src/string.c	6 Jul 2007 21:52:39 -0000	1.10
+++ Src/string.c	28 Feb 2011 11:51:46 -0000
@@ -64,7 +64,7 @@ wcs_ztrdup(const wchar_t *s)
 
     if (!s)
 	return NULL;
-    t = (wchar_t *)zalloc(wcslen((wchar_t *)s) + 1);
+    t = (wchar_t *)zalloc(sizeof(wchar_t) * (wcslen((wchar_t *)s) + 1));
     wcscpy(t, s);
     return t;
 }

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


  reply	other threads:[~2011-02-28 11:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-28 10:35 Frank Terbeck
2011-02-28 11:55 ` Peter Stephenson [this message]
2011-02-28 12:04   ` Frank Terbeck

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=20110228115510.29590f1d@pwslap01u.europe.root.pri \
    --to=peter.stephenson@csr.com \
    --cc=zsh-workers@zsh.org \
    /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).