From 62a05c087f5d80575b64e672714bd328c87e42df 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 | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 9f328a377321..c54cd9fa7533 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,15 +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; - } - if (width <= 0) { printf("%lc", wc); continue;