From a02687a83ea6dafe17cd538ab1f9d96d1d6ae877 Mon Sep 17 00:00:00 2001 From: Sylvie <35663410+Rangi42@users.noreply.github.com> Date: Mon, 19 Feb 2024 02:09:55 -0500 Subject: [PATCH] Fix behavior of non-ASCII bytes with `INCHARMAP` (#1308) --- src/asm/charmap.cpp | 4 ++-- test/asm/charmap-unicode.asm | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 test/asm/charmap-unicode.asm diff --git a/src/asm/charmap.cpp b/src/asm/charmap.cpp index 71ced275..f6b94790 100644 --- a/src/asm/charmap.cpp +++ b/src/asm/charmap.cpp @@ -180,7 +180,7 @@ bool charmap_HasChar(char const *input) struct Charnode const *node = &charmap->nodes[0]; for (; *input; input++) { - size_t next = node->next[*input - 1]; + size_t next = node->next[(uint8_t)*input - 1]; if (!next) return false; @@ -212,7 +212,7 @@ size_t charmap_ConvertNext(char const **input, uint8_t **output) size_t rewindDistance = 0; for (;;) { - uint8_t c = **input - 1; + uint8_t c = (uint8_t)**input - 1; if (**input && node->next[c]) { // Consume that char diff --git a/test/asm/charmap-unicode.asm b/test/asm/charmap-unicode.asm new file mode 100644 index 00000000..e7867420 --- /dev/null +++ b/test/asm/charmap-unicode.asm @@ -0,0 +1,11 @@ +MACRO test + charmap \1, 42 + assert charlen(\1) == 1 + assert incharmap(\1) == 1 +ENDM + + test "a" ; one ASCII + test "hi~!!1" ; many ASCII + test "デ" ; one UTF-8 + test "グレイシア" ; many UTF-8 + test "Pokémon" ; mixed