From f1257fb7fc458555430ae6cf76f7b1a7a329e47d Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Tue, 24 May 2022 11:51:18 -0700 Subject: [PATCH] Fixed some of invalid utf8 --- BeefLibs/Beefy2D/src/widgets/EditWidget.bf | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/BeefLibs/Beefy2D/src/widgets/EditWidget.bf b/BeefLibs/Beefy2D/src/widgets/EditWidget.bf index af154d51..b8217aa1 100644 --- a/BeefLibs/Beefy2D/src/widgets/EditWidget.bf +++ b/BeefLibs/Beefy2D/src/widgets/EditWidget.bf @@ -703,6 +703,11 @@ namespace Beefy.widgets EditWidgetContent.CharData* readPtr = &mData.mText[idx + 1]; int trailingBytes = UTF8.sTrailingBytesForUTF8[c]; + if (idx + trailingBytes + 1 >= mData.mTextLength) + { + return (c, 1); + } + switch (trailingBytes) { case 4: c <<= 6; c += (uint8)(readPtr++).mChar; fallthrough; @@ -3507,6 +3512,12 @@ namespace Beefy.widgets } if (movingDir > 0) { + if ((useCharIdx == charIdx) && (c < (.)0xC0)) + { + // This is an invalid UTF8 sequence + break; + } + useCharIdx++; mCursorTextPos++; }