git: gpt(8): Fix surrogate pair handling bug in utf16_to_utf8()
Aaron LI
aly at crater.dragonflybsd.org
Wed Feb 18 06:32:42 PST 2026
commit 62207d04fe9a976a6127b4950ed82632bd154815
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/62207d04fe9a976a6127b4950ed82632bd154815
--
DragonFly BSD source repository
More information about the Commits
mailing list