diff options
author | VanaIgr <vanaigranov@gmail.com> | 2024-02-26 04:12:55 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-26 18:12:55 +0800 |
commit | ad5a155b1f4b387d3aaa54c91d0146cb0287bb9f (patch) | |
tree | ae35dff22d4f418f040d39acc88206e64ffb1984 /src/nvim/mbyte.h | |
parent | 8b4e26915612caf2d143edca31919cae18a848a1 (diff) | |
download | rneovim-ad5a155b1f4b387d3aaa54c91d0146cb0287bb9f.tar.gz rneovim-ad5a155b1f4b387d3aaa54c91d0146cb0287bb9f.tar.bz2 rneovim-ad5a155b1f4b387d3aaa54c91d0146cb0287bb9f.zip |
fix(mbyte): fix bugs in utf_cp_*_off() functions
Problems:
- Illegal bytes after valid UTF-8 char cause utf_cp_*_off() to fail.
- When stream isn't NUL-terminated, utf_cp_*_off() may go over the end.
Solution: Don't go over end of the char of end of the string.
Diffstat (limited to 'src/nvim/mbyte.h')
-rw-r--r-- | src/nvim/mbyte.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/nvim/mbyte.h b/src/nvim/mbyte.h index 2f17c706c1..ddac040aae 100644 --- a/src/nvim/mbyte.h +++ b/src/nvim/mbyte.h @@ -52,6 +52,16 @@ extern const uint8_t utf8len_tab[256]; #define MB_PTR_BACK(s, p) \ (p -= utf_head_off((char *)(s), (char *)(p) - 1) + 1) +/// Check whether a given UTF-8 byte is a trailing byte (10xx.xxxx). +static inline bool utf_is_trail_byte(uint8_t byte) + REAL_FATTR_CONST REAL_FATTR_ALWAYS_INLINE; + +static inline bool utf_is_trail_byte(uint8_t const byte) +{ + // uint8_t is for clang to use smaller cmp + return (uint8_t)(byte & 0xC0U) == 0x80U; +} + static inline CharInfo utf_ptr2CharInfo(char const *p_in) REAL_FATTR_NONNULL_ALL REAL_FATTR_PURE REAL_FATTR_WARN_UNUSED_RESULT REAL_FATTR_ALWAYS_INLINE; |