1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

added check for utf_len in inp_get_char

This commit is contained in:
Dmitry Podgorny 2013-01-06 00:56:59 +02:00
parent ad000db663
commit d870ea1ae6

View File

@ -198,12 +198,16 @@ inp_get_char(char *input, int *size)
} else { } else {
char bytes[MB_CUR_MAX+1]; char bytes[MB_CUR_MAX+1];
size_t utf_len = wcrtomb(bytes, ch, NULL); size_t utf_len = wcrtomb(bytes, ch, NULL);
// wcrtomb can return (size_t) -1
if (utf_len < MB_CUR_MAX) {
for (i = 0 ; i < utf_len; i++) { for (i = 0 ; i < utf_len; i++) {
input[(*size)++] = bytes[i]; input[(*size)++] = bytes[i];
} }
input[*size] = '\0';
bytes[utf_len] = '\0'; bytes[utf_len] = '\0';
wprintw(inp_win, bytes); wprintw(inp_win, bytes);
display_size++; display_size++;
// if gone over screen size follow input // if gone over screen size follow input
@ -214,6 +218,7 @@ inp_get_char(char *input, int *size)
prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1); prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
} }
} }
}
cmd_reset_autocomplete(); cmd_reset_autocomplete();
} }