-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ToString and ToWString on large strings (#5930)
## Summary of changes Fix ToString and ToWString on large strings ## Reason for change Those two methods have a fast-path, where we try to fit the result in a pre-allocated buffer. But when the string is too long, we incorrectly assumed that `WideCharToMultiByte`/`MultiByteToWideChar` would return the needed size. In truth, [it only does so when `cchWideChar` is 0](https://learn.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-multibytetowidechar#return-value). Because of that mistake, we were returning an empty string. ## Implementation details Added a few minor changes while I was at it: - For arrays, directly use the array instead of `&array[0]` - For strings, use `str.data()` instead of `&str[0]` - Don't zero the buffer since we're going to only use what is filled ## Test coverage Added a unit test for long strings.
- Loading branch information
1 parent
4531f1b
commit e0d9add
Showing
2 changed files
with
23 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters