git: DragonFly_RELEASE_6_4 gpt(8): Fix surrogate pair handling bug in utf16_to_utf8()
Aaron LI
aly at crater.dragonflybsd.org
Sat Feb 21 17:07:06 PST 2026
commit c795974618e293268274565309d8f35028684fe0
Author: Aaron LI <aly at aaronly.me>
Date: Wed Jan 21 17:17:55 2026 +0800
gpt(8): Fix surrogate pair handling bug in utf16_to_utf8()
* The old code mishandled surrogate pairs and thus failed to recognize
valid UTF-16 characters and would replace them with 0xFFFD. Fix the
code to correctly handle the surrogate pairs.
* Fix an out-of-bound access in the old code when it tried to handle the
surrogate pairs. Check `s16idx < s16len` before accessing it with
`le16toh(s16[s16idx])`.
* Remove the `if (utfchar < 0x200000)` branch, because it's impossible
for `utfchar` exceeding 0x200000.
* Tweak the `while` loop conditional to clean up the code.
Credit: ChatGPT (https://chatgpt.com/)
Summary of changes:
sbin/gpt/gpt.c | 40 +++++++++++++++++++++++++---------------
1 file changed, 25 insertions(+), 15 deletions(-)
http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/c795974618e293268274565309d8f35028684fe0
--
DragonFly BSD source repository
More information about the Commits
mailing list