fix: BlackWriter writes invalid files on systems where wchar_t is UTF-32 - #8
Open
TrueBrain wants to merge 1 commit into
Open
fix: BlackWriter writes invalid files on systems where wchar_t is UTF-32#8TrueBrain wants to merge 1 commit into
TrueBrain wants to merge 1 commit into
Conversation
On Windows, wchar_t is UTF-16 (2 bytes/char). On Linux / MacOS, it is UTF-32 (4 bytes/char). BlackReader assumes UTF-16, but on Linux / MacOS, BlackWriter was writing UTF-32 instead.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Windows, wchar_t is UTF-16 (2 bytes/char). On Linux / MacOS, it is UTF-32 (4 bytes/char). BlackReader assumes UTF-16, but on Linux / MacOS, BlackWriter was writing UTF-32 instead.
Somewhat related: the BlackReader doesn't decode UTF-16 into UTF-32, but instead simply widens it. The BlackWriter (after this PR) truncate UTF-32 into UTF-16 (instead of encoding). This works fine until someone tries to use emojis (or any other codepoint outside BMP).
The proper solution is to do proper UTF-32 <-> UTF-16 encoding for MacOS / Linux. But this is more involved, so I wanted to get this bug-fix out of the way first, before working on properly supporting surrogate pairs (for both reading and writing).
And as BlackReader is broken already, I simply assumed nobody has been using emojis in their black/red files anyway :D
Full disclosure: I am employed by Fenris Creations, although I have no involvement with the Carbon project. I work on this in my free time under my own name.