From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10 Path: news.gmane.org!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: Re: wcsncpy bug Date: Mon, 23 May 2011 04:10:22 +0200 Message-ID: <20110523021022.GI6142@port70.net> References: <20110523012547.GH6142@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1306116656 21715 80.91.229.12 (23 May 2011 02:10:56 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 23 May 2011 02:10:56 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-93-gllmg-musl=m.gmane.org@lists.openwall.com Mon May 23 04:10:48 2011 Return-path: Envelope-to: gllmg-musl@lo.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by lo.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1QOKbU-0007zh-To for gllmg-musl@lo.gmane.org; Mon, 23 May 2011 04:10:45 +0200 Original-Received: (qmail 32649 invoked by uid 550); 23 May 2011 02:10:44 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 32641 invoked from network); 23 May 2011 02:10:44 -0000 Content-Disposition: inline In-Reply-To: <20110523012547.GH6142@port70.net> User-Agent: Mutt/1.5.20 (2009-06-14) Xref: news.gmane.org gmane.linux.lib.musl.general:10 Archived-At: * Szabolcs Nagy [2011-05-23 03:25:47 +0200]: > wchar_t *wcsncpy(wchar_t *d, const wchar_t *s, size_t n) > { > wchar_t *a = d; > - while (n && (*d++ = *s++)) n--; > + while (n-- && (*d++ = *s++)); hm this code is not ok if n underflows here.. > wmemset(d, 0, n); > return a; > } let me try again.. maybe you can figure out a nicer one wchar_t *wcsncpy(wchar_t *d, const wchar_t *s, size_t n) { wchar_t *a = d; while (n && *s) { *d++ = *s++; n--; } wmemset(d, 0, n); return a; }