diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-05-20 16:51:57 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2020-05-20 16:51:57 (GMT) |
commit | 38d1c0b4e30e546ebe17c179e46e99884dcab433 (patch) | |
tree | 626a91a7efdd0b61978a1ff2c0ccf262ada91491 /generic/tkCanvText.c | |
parent | 51d384bfda7a3eb5a915b19d343c8bb657268d75 (diff) | |
parent | 75d83ece93c7c0f3a2a3c8e3a925b35353ccddeb (diff) | |
download | tk-38d1c0b4e30e546ebe17c179e46e99884dcab433.zip tk-38d1c0b4e30e546ebe17c179e46e99884dcab433.tar.gz tk-38d1c0b4e30e546ebe17c179e46e99884dcab433.tar.bz2 |
Add (and use) new internal function TkUtfAtIndex(), which does the same as Tcl_UtfAtIndex() only it protects against ending in the middle of a 4-byte UTF-8 sequence. This should fix another part of [a179564826] when handling copy-pasted Emoji in Text/Entry (and other) widgets.
Diffstat (limited to 'generic/tkCanvText.c')
-rw-r--r-- | generic/tkCanvText.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/generic/tkCanvText.c b/generic/tkCanvText.c index 1e58ce9..9a27efc 100644 --- a/generic/tkCanvText.c +++ b/generic/tkCanvText.c @@ -1025,7 +1025,7 @@ TextInsert( if (index > textPtr->numChars) { index = textPtr->numChars; } - byteIndex = Tcl_UtfAtIndex(text, index) - text; + byteIndex = TkUtfAtIndex(text, index) - text; byteCount = strlen(string); if (byteCount == 0) { return; @@ -1108,8 +1108,8 @@ TextDeleteChars( } charsRemoved = last + 1 - first; - byteIndex = Tcl_UtfAtIndex(text, first) - text; - byteCount = Tcl_UtfAtIndex(text + byteIndex, charsRemoved) + byteIndex = TkUtfAtIndex(text, first) - text; + byteCount = TkUtfAtIndex(text + byteIndex, charsRemoved) - (text + byteIndex); newStr = ckalloc(textPtr->numBytes + 1 - byteCount); @@ -1497,8 +1497,8 @@ GetSelText( return 0; } text = textPtr->text; - selStart = Tcl_UtfAtIndex(text, textInfoPtr->selectFirst); - selEnd = Tcl_UtfAtIndex(selStart, + selStart = TkUtfAtIndex(text, textInfoPtr->selectFirst); + selEnd = TkUtfAtIndex(selStart, textInfoPtr->selectLast + 1 - textInfoPtr->selectFirst); byteCount = selEnd - selStart - offset; if (byteCount > maxBytes) { |