1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-09 21:30:42 +00:00

Input window: handle invalid multibyte

The current code enters an infinite loop if the input string happens
to get an invalid utf-8 sequence somehow. For me it was reproducible
by running profanity in a Screen session and pressing Alt-т (cyrillic
letter).

Fix it the way borrowed from 0501e49623
where mbrlen is used for the same purposes.
This commit is contained in:
Paul Fertser 2022-03-29 13:38:02 +03:00
parent 3ee3d78af5
commit 1e81eea899

View File

@ -373,6 +373,10 @@ _inp_offset_to_col(char* str, int offset)
while (i < offset && str[i] != '\0') {
gunichar uni = g_utf8_get_char(&str[i]);
size_t ch_len = mbrlen(&str[i], MB_CUR_MAX, NULL);
if ((ch_len == (size_t)-2) || (ch_len == (size_t)-1)) {
i++;
continue;
}
i += ch_len;
col++;
if (g_unichar_iswide(uni)) {