about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorPaul Fertser <fercerpav@gmail.com>2022-03-29 13:38:02 +0300
committerPaul Fertser <fercerpav@gmail.com>2022-03-29 13:57:07 +0300
commit1e81eea8990ca1e2370cde591a23e87c866d8000 (patch)
treec9431ea3154ad485fd018aa264e431f6d25a1f81 /src
parent3ee3d78af58f62d3dd2587190992c9465b9b416e (diff)
downloadprofani-tty-1e81eea8990ca1e2370cde591a23e87c866d8000.tar.gz
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 0501e49623f68aa39508e4e622924c1dd8147588
where mbrlen is used for the same purposes.
Diffstat (limited to 'src')
-rw-r--r--src/ui/inputwin.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c
index d19d8719..ac7cf817 100644
--- a/src/ui/inputwin.c
+++ b/src/ui/inputwin.c
@@ -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)) {