mirror of
https://github.com/apache/nuttx.git
synced 2026-05-23 06:39:01 +08:00
libc/wcsrtombs: Fix the wcsrtombs() according to the POSIX standard
According to https://pubs.opengroup.org/onlinepubs/9799919799/, the expected behavior for the wcstombs() function is that it should convert the wide-character codes stoping conversion either when a character sequence exceeds the limit of n total bytes or if a null byte is stored. In the first case, the null-terminated value should not be appended to the dst buffer. Currently, no null-terminator is appended to the dst buffer, even when it's expected to be appended, generating erroneous output.
This commit is contained in:
committed by
Alin Jerpelea
parent
0ae633cc08
commit
fdc0b608b5
@@ -40,5 +40,14 @@
|
||||
size_t wcsrtombs(FAR char *dst, FAR const wchar_t **src,
|
||||
size_t len, FAR mbstate_t *ps)
|
||||
{
|
||||
return wcsnrtombs(dst, src, SIZE_MAX, len, ps);
|
||||
size_t ret;
|
||||
|
||||
ret = wcsnrtombs(dst, src, SIZE_MAX, len, ps);
|
||||
|
||||
if (dst != NULL && ret != (size_t)-1 && ret != len)
|
||||
{
|
||||
dst[ret] = '\0';
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user