This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Bug in wcsncpy
- From: Martin Sjöstedt <Martin dot Sjostedt at ascom dot se>
- To: <newlib at sourceware dot org>
- Date: Mon, 17 Aug 2009 14:13:28 +0200
- Subject: Bug in wcsncpy
Hi!
We have discovered a problem with wcsncpy(s1, s2, n). The documentation states that the function shall copy no more than n wide characters from s2 into s1, and if less than n characters copied s1 shall be filled with zeroes up to n.
But the current implementation in newlib,
p = s1;
q = s2;
while (n && *q)
{
*p++ = *q++;
n--;
}
*p = '\0';
, does copy n characters into s1 and then always puts one zero at the end (which might be s1[n+1]).
In a newer version of this file found in OpenBSD this is implemented like this:
p = s1;
while (n && *s2) {
*p++ = *s2++;
n--;
}
while (n) {
*p++ = L'\0';
n--;
}
Are there any plans on changing this?
Best Regards,
Martin
Please consider the environment before printing this e-mail and any associated attachments