[TD-5056]<fix> fix input exception

This commit is contained in:
plum-lihui 2021-07-07 16:41:04 +08:00
parent 1aa2019d4c
commit 7f3654bdfc
2 changed files with 3 additions and 3 deletions

View File

@ -45,7 +45,7 @@ extern void updateBuffer(Command *cmd);
extern int isReadyGo(Command *cmd); extern int isReadyGo(Command *cmd);
extern void resetCommand(Command *cmd, const char s[]); extern void resetCommand(Command *cmd, const char s[]);
int countPrefixOnes(char c); int countPrefixOnes(unsigned char c);
void clearScreen(int ecmd_pos, int cursor_pos); void clearScreen(int ecmd_pos, int cursor_pos);
void printChar(char c, int times); void printChar(char c, int times);
void positionCursor(int step, int direction); void positionCursor(int step, int direction);

View File

@ -26,7 +26,7 @@ typedef struct {
char widthOnScreen; char widthOnScreen;
} UTFCodeInfo; } UTFCodeInfo;
int countPrefixOnes(char c) { int countPrefixOnes(unsigned char c) {
unsigned char mask = 127; unsigned char mask = 127;
mask = ~mask; mask = ~mask;
int ret = 0; int ret = 0;
@ -48,7 +48,7 @@ void getPrevCharSize(const char *str, int pos, int *size, int *width) {
while (--pos >= 0) { while (--pos >= 0) {
*size += 1; *size += 1;
if (str[pos] > 0 || countPrefixOnes(str[pos]) > 1) break; if (str[pos] > 0 || countPrefixOnes((unsigned char )str[pos]) > 1) break;
} }
int rc = mbtowc(&wc, str + pos, MB_CUR_MAX); int rc = mbtowc(&wc, str + pos, MB_CUR_MAX);