提交 39d0226b 编写于 作者: wmmhello's avatar wmmhello

fix dead loop if shell character is invalidate

上级 b62d3759
...@@ -565,9 +565,12 @@ static void shellPrintNChar(const char *str, int length, int width) { ...@@ -565,9 +565,12 @@ static void shellPrintNChar(const char *str, int length, int width) {
if (bytes <= 0) { if (bytes <= 0) {
break; break;
} }
if (pos + bytes > length) {
break;
}
int w = 0; int w = 0;
#ifdef WINDOWS #ifdef WINDOWS
w = bytes; w = bytes;gdn
#else #else
if(*(str + pos) == '\t' || *(str + pos) == '\n' || *(str + pos) == '\r'){ if(*(str + pos) == '\t' || *(str + pos) == '\n' || *(str + pos) == '\r'){
w = bytes; w = bytes;
...@@ -575,15 +578,11 @@ static void shellPrintNChar(const char *str, int length, int width) { ...@@ -575,15 +578,11 @@ static void shellPrintNChar(const char *str, int length, int width) {
w = wcwidth(wc); w = wcwidth(wc);
} }
#endif #endif
pos += bytes;
if (w <= 0) { if (w <= 0) {
continue; continue;
} }
pos += bytes;
if (pos > length) {
break;
}
if (width <= 0) { if (width <= 0) {
printf("%lc", wc); printf("%lc", wc);
continue; continue;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册