Skip to content

Fix PDC_wcstombs() for an output that exactly fills the buffer - #391

Open
serhiy-storchaka wants to merge 1 commit into
Bill-Gray:masterfrom
serhiy-storchaka:fix-wcstombs-exact-fit
Open

serhiy-storchaka wants to merge 1 commit into
Bill-Gray:masterfrom
serhiy-storchaka:fix-wcstombs-exact-fit

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Contributor

wcstombs() returns n when the converted string fills all n bytes; that is a complete conversion, not an error, so terminate at dest[n] as before ea9baa4 instead of zeroing *dest. Also detect the failure as i == (size_t)-1 rather than by casting a size_t to int.

With the vt port: PDC_wcstombs(buf, L"ABCDE", 5) gave "\0BCDE" (and fails the assert in a build with assertions); it now gives "ABCDE", and an unencodable input still returns (size_t)-1 with an empty dest.

Fixes #390.

wcstombs() returns n when the converted string fills all n bytes;
that is not an error.  Also compare the result with (size_t)-1
instead of casting it to int.  Fixes Bill-Gray#390.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PDC_wcstombs() zeroes the first byte when the output exactly fills the buffer (regression in ea9baa42)

1 participant