From 5c97cd8ddab62c066211ec1cd61f9cbd55dca791 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Thu, 10 Mar 2022 17:40:36 +0800 Subject: [PATCH] [TS-1306]: fix endless loop with utf-8 replacement character --- src/kit/shell/src/shellEngine.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 9f328a377321..028643446f71 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -545,6 +545,9 @@ static void shellPrintNChar(const char *str, int length, int width) { if (bytes <= 0) { break; } + if (pos + bytes > length) { + break; + } int w = 0; #ifdef WINDOWS w = bytes; @@ -555,11 +558,11 @@ static void shellPrintNChar(const char *str, int length, int width) { w = wcwidth(wc); } #endif + pos += bytes; if (w <= 0) { continue; } - pos += bytes; if (pos > length) { break; }