This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Attached is a patch to correct the problem. I adapted the code from the short version of strncpy(), which is very similar to the OpenBSD example that Martin quoted. I also made some small tweaks to the documentation. Craig -----Original Message----- From: newlib-owner@sourceware.org [mailto:newlib-owner@sourceware.org] On Behalf Of Martin Sjöstedt Sent: Monday, August 17, 2009 8:13 AM To: newlib@sourceware.org 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
Attachment:
wcsncpy.patch
Description: wcsncpy.patch
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |