Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix MultiByte <-> WideChar conversion return value on linux #6725

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

exoticorn
Copy link

MultiByteToWideChar/WideCharToMultiByte are supposed to include/exclude null termination based on whether the source string buffer is null terminated.

This was done by comparing the input byte/wide character count to the output byte/wide character count excluding null termination. This only works correctly if the input only consists of ASCII characters. (ie. only characters that are single byte in UTF-8)

This commit changes the code to explicitly check for a null terminator in the input and add one to the output size if the input was terminated.

MultiByteToWideChar/WideCharToMultiByte are supposed to include/exclude null termination
based on whether the source string buffer is null terminated.

This was done by comparing the input byte/wide character count to the output byte/wide
character count excluding null termination. This only works correctly if the input only
consists of ASCII characters. (ie. only characters that are single byte in UTF-8)

This commit changes the code to explicitly check for a null terminator in the input
and add one to the output size if the input was terminated.
@exoticorn exoticorn requested a review from a team as a code owner June 26, 2024 08:51
@exoticorn
Copy link
Author

@microsoft-github-policy-service agree company="Keen Games GmbH"

@exoticorn
Copy link
Author

Without this fix, I ran into the assert

    DXASSERT(
        !utf8CharCount ||
            IsBufferNullTerminated(utf8NewCopy.m_pData, utf8CharCount, CP_UTF8),
        "otherwise, CodePageBufferToUtf8 failed to null-terminate buffer.");

in DxcGetBlobAsUtf8 when loading a shader source that includes exactly one two-byte utf-8 character.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New
Development

Successfully merging this pull request may close these issues.

1 participant