From be7e171597b21f6a572f5027f7e1feeb52ec27fb Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Mon, 27 Jun 2022 00:00:00 -0500 Subject: [PATCH] top: if line editing, account for invisible characters <=== port of newlib b0adacf1 ______________________________ original newlib message If we're deleting a character or operating in overtype mode, we must account for the potential of 'invisible' characters. When one follows any character about to be deleted or replaced both multi-byte sequences must go. Without this change, there exists the possibility that top might report some error where no error is apparent to the user. For example, with 'other filtering' (o/O) the user could see "unrecognized field name 'COMMAND'" where the quoted column name appears perfectly normal. Or maybe a sequences like the 'combining acute accent' gets applied to an existing character instead of being deleted as one expects when its parent was eliminated. So, henceforth whenever any character is being deleted we will now check for a following 'invisible' sequence then eliminate it along with that preceding character. [ admittedly, these scenarios are very rare yet they ] [ may occur, especially when recalling some previous ] [ multi-byte strings for editing. and, since we will ] [ be interacting with a user, performance won't be a ] [ factor so extra checks for a zero wcwidth is fine. ] Signed-off-by: Jim Warner --- top/top.c | 1 + 1 file changed, 1 insertion(+) diff --git a/top/top.c b/top/top.c index d6c80602..1a899cd6 100644 --- a/top/top.c +++ b/top/top.c @@ -1337,6 +1337,7 @@ static char *ioline (const char *prompt) { #define chkCUR { if (cur < 0) cur = 0; if (cur > len) cur = len; } // thank goodness ol' memmove will safely allow strings to overlap #define sqzSTR { i = utfTOT(pos); while (i < 0) i = utfTOT(--pos); \ + if (!utfCOL(pos + i)) i += utfTOT(pos + i); \ memmove(&buf[pos], &buf[pos + i], bufMAX-(pos + i)); \ memset(&buf[bufMAX - i], '\0', i); } #define expSTR(X) if (bufNXT < bufMAX && scrNXT < Screen_cols) { \