Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20110523021022.GI6142@port70.net>
Date: Mon, 23 May 2011 04:10:22 +0200
From: Szabolcs Nagy <nsz@...t70.net>
To: musl@...ts.openwall.com
Subject: Re: wcsncpy bug

* Szabolcs Nagy <nsz@...t70.net> [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;
}

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.