Skip to content

fix: BlackWriter writes invalid files on systems where wchar_t is UTF-32 - #8

Open
TrueBrain wants to merge 1 commit into
carbonengine:mainfrom
TrueBrain:push-uowpqslyvsrp
Open

fix: BlackWriter writes invalid files on systems where wchar_t is UTF-32#8
TrueBrain wants to merge 1 commit into
carbonengine:mainfrom
TrueBrain:push-uowpqslyvsrp

Conversation

@TrueBrain

@TrueBrain TrueBrain commented Jul 31, 2026

Copy link
Copy Markdown

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.

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.
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.

1 participant