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 utf8_decode failing on 16-bit codepoints at end of string #184

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

Conversation

jcl1234
Copy link

@jcl1234 jcl1234 commented Apr 2, 2024

utf8_decode's 16-bit case checks for max >= 3 rather than max >= 2, which means the sequence will fail to decode if max = 2 (E.g. when the sequence is the last in a string).

Example:

// 'å' & 'ñ' are each encoded in utf8 using a 16-bit sequence.
// str16_from_8 calls utf8_decode internally.
Temp scratch = scratch_begin(0, 0);
String16 result = str16_from_8(scratch.arena, str8_lit("å ñ"));

Expected result:

{
  .str = {0x00e5, 0x0020, 0x00f1}, // "å ñ"
  .size = 3
}

Actual result:

{
  .str = {0x00e5, 0x0020, 0x003f, 0x003f}, // "å ??"
  .size = 4
}

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